<|start_filename|>thirdparty/jfoenix-commons/tests/src/ktfx/jfoenix/controls/JFXTableColumnsTest.kt<|end_filename|>
package ktfx.jfoenix.controls

import com.hendraanggrian.ktfx.test.TableColumnTest

class JFXTableColumnsTest : TableColumnTest() {

}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/TreeTableViewTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.TreeTableView
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class TreeTableViewTest : LayoutsTest<KtfxPane, TreeTableView<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = treeTableView<String> { }
    override fun KtfxPane.child2() = treeTableView<String>()
    override fun KtfxPane.child3() = treeTableView<String> { }

    override fun TreeTableView<String>.testDefaultValues() {
        assertNull(root)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/EllipseTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.Ellipse
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class EllipseTest : LayoutsTest<KtfxPane, Ellipse>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = ellipse { }
    override fun KtfxPane.child2() = ellipse()
    override fun KtfxPane.child3() = ellipse { }

    override fun Ellipse.testDefaultValues() {
        assertEquals(0.0, centerX)
        assertEquals(0.0, centerY)
        assertEquals(0.0, radiusX)
        assertEquals(0.0, radiusY)
    }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_TitledPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.TitledPane
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [TitledPane] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.titledPane(title: String? = null): TitledPane = titledPane(title = title) { }

/**
 * Add a [TitledPane] to this manager.
 *
 * @return the control added.
 */
public fun TitledPaneManager.titledPane(title: String? = null): TitledPane = titledPane(
    title =
    title
) { }

/**
 * Create a [TitledPane] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun titledPane(
    title: String? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        KtfxTitledPane
    ).() -> Unit
): TitledPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTitledPane(title)
    child.configuration()
    return child
}

/**
 * Add a [TitledPane] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.titledPane(
    title: String? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        KtfxTitledPane
    ).() -> Unit
): TitledPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTitledPane(title)
    child.configuration()
    return addChild(child)
}

/**
 * Add a [TitledPane] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun TitledPaneManager.titledPane(
    title: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxTitledPane).() -> Unit
): TitledPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTitledPane(title)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [TitledPane].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledTitledPane(
    title: String? = null,
    vararg styleClass: String,
    id: String? = null
): TitledPane = styledTitledPane(title = title, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [TitledPane] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledTitledPane(
    title: String? = null,
    vararg styleClass: String,
    id: String? = null
): TitledPane = styledTitledPane(title = title, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [TitledPane] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun TitledPaneManager.styledTitledPane(
    title: String? = null,
    vararg styleClass: String,
    id: String? = null
): TitledPane = styledTitledPane(title = title, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [TitledPane] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledTitledPane(
    title: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxTitledPane).() -> Unit
): TitledPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTitledPane(title)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [TitledPane] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledTitledPane(
    title: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxTitledPane).() -> Unit
): TitledPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTitledPane(title)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}

/**
 * Add a styled [TitledPane] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun TitledPaneManager.styledTitledPane(
    title: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxTitledPane).() -> Unit
): TitledPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTitledPane(title)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-listeners/src/ktfx/jfoenix/listeners/_JFXAutoCompletePopup.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.jfoenix.listeners

import com.jfoenix.controls.JFXAutoCompletePopup
import com.jfoenix.controls.events.JFXAutoCompleteEvent
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see JFXAutoCompletePopup.setSelectionHandler
 */
public inline fun <T> JFXAutoCompletePopup<T>.selectionHandler(
    noinline
    action: (JFXAutoCompleteEvent<T>) -> Unit
) {
    return setSelectionHandler(action)
}


<|start_filename|>ktfx-coroutines/src/javafx/collections/ObservableMap.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxCoroutinesKt")

package ktfx.coroutines

import javafx.collections.MapChangeListener
import javafx.collections.ObservableMap
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

/** Add a listener to this observable map. */
fun <K, V> ObservableMap<K, V>.listener(
    context: CoroutineContext = Dispatchers.JavaFx,
    listener: suspend CoroutineScope.(MapChangeListener.Change<out K, out V>) -> Unit
): MapChangeListener<K, V> = MapChangeListener<K, V> { change ->
    GlobalScope.launch(context) { listener(change) }
}.also { addListener(it) }


<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/TabTest.kt<|end_filename|>
package ktfx.listeners

import javafx.event.Event
import javafx.scene.control.Tab
import com.hendraanggrian.ktfx.test.BaseTabTest

class TabTest : BaseTabTest() {

    override fun Tab.callOnSelectionChanged(action: (Event) -> Unit) = onSelectionChanged(action)
    override fun Tab.callOnClosed(action: (Event) -> Unit) = onClosed(action)
    override fun Tab.callOnCloseRequest(action: (Event) -> Unit) = onCloseRequest(action)
}

<|start_filename|>testing/listeners-coroutines/src/javafx/stage/BaseWindowTest.kt<|end_filename|>
package javafx.stage

import com.hendraanggrian.ktfx.test.testScene
import org.testfx.framework.junit.ApplicationTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseWindowTest : ApplicationTest() {
    private lateinit var window: Window

    abstract fun Window.callOnCloseRequest(action: (WindowEvent) -> Unit)
    abstract fun Window.callOnShowing(action: (WindowEvent) -> Unit)
    abstract fun Window.callOnShown(action: (WindowEvent) -> Unit)
    abstract fun Window.callOnHiding(action: (WindowEvent) -> Unit)
    abstract fun Window.callOnHidden(action: (WindowEvent) -> Unit)

    override fun start(stage: Stage) {
        stage.testScene<Window>()
        window = stage
    }

    @Test
    fun onCloseRequest() {
        window.callOnCloseRequest {
            assertEquals(window, it.source)
            assertEquals(WindowEvent.WINDOW_CLOSE_REQUEST, it.eventType)
        }
        window.onCloseRequest.handle(WindowEvent(window, WindowEvent.WINDOW_CLOSE_REQUEST))
    }

    @Test
    fun onShowing() {
        window.callOnShowing {
            assertEquals(window, it.source)
            assertEquals(WindowEvent.WINDOW_SHOWING, it.eventType)
        }
        window.onShowing.handle(WindowEvent(window, WindowEvent.WINDOW_SHOWING))
    }

    @Test
    fun onShown() {
        window.callOnShown {
            assertEquals(window, it.source)
            assertEquals(WindowEvent.WINDOW_SHOWN, it.eventType)
        }
        window.onShown.handle(WindowEvent(window, WindowEvent.WINDOW_SHOWN))
    }

    @Test
    fun onHiding() {
        window.callOnHiding {
            assertEquals(window, it.source)
            assertEquals(WindowEvent.WINDOW_HIDING, it.eventType)
        }
        window.onHiding.handle(WindowEvent(window, WindowEvent.WINDOW_HIDING))
    }

    @Test
    fun onHidden() {
        window.callOnHidden {
            assertEquals(window, it.source)
            assertEquals(WindowEvent.WINDOW_HIDDEN, it.eventType)
        }
        window.onHidden.handle(WindowEvent(window, WindowEvent.WINDOW_HIDDEN))
    }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_CubicCurve.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.CubicCurve
import kotlin.Double
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [CubicCurve] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.cubicCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX1: Double = 0.0,
    controlY1: Double = 0.0,
    controlX2: Double = 0.0,
    controlY2: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0
): CubicCurve = cubicCurve(
    startX = startX, startY = startY, controlX1 = controlX1,
    controlY1 =
    controlY1,
    controlX2 = controlX2, controlY2 = controlY2, endX = endX, endY = endY
) { }

/**
 * Create a [CubicCurve] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun cubicCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX1: Double = 0.0,
    controlY1: Double = 0.0,
    controlX2: Double = 0.0,
    controlY2: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker CubicCurve).() -> Unit
): CubicCurve {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CubicCurve(startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY)
    child.configuration()
    return child
}

/**
 * Add a [CubicCurve] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.cubicCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX1: Double = 0.0,
    controlY1: Double = 0.0,
    controlX2: Double = 0.0,
    controlY2: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker CubicCurve).() -> Unit
): CubicCurve {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CubicCurve(startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [CubicCurve].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledCubicCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX1: Double = 0.0,
    controlY1: Double = 0.0,
    controlX2: Double = 0.0,
    controlY2: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): CubicCurve = styledCubicCurve(
    startX = startX, startY = startY, controlX1 = controlX1,
    controlY1 =
    controlY1,
    controlX2 = controlX2, controlY2 = controlY2, endX = endX, endY = endY,
    styleClass = *styleClass, id = id
) { }

/**
 * Add a styled [CubicCurve] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledCubicCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX1: Double = 0.0,
    controlY1: Double = 0.0,
    controlX2: Double = 0.0,
    controlY2: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): CubicCurve = styledCubicCurve(
    startX = startX, startY = startY, controlX1 = controlX1,
    controlY1 =
    controlY1,
    controlX2 = controlX2, controlY2 = controlY2, endX = endX, endY = endY,
    styleClass = *styleClass, id = id
) { }

/**
 * Create a styled [CubicCurve] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledCubicCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX1: Double = 0.0,
    controlY1: Double = 0.0,
    controlX2: Double = 0.0,
    controlY2: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker CubicCurve).() -> Unit
): CubicCurve {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CubicCurve(startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [CubicCurve] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledCubicCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX1: Double = 0.0,
    controlY1: Double = 0.0,
    controlX2: Double = 0.0,
    controlY2: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker CubicCurve).() -> Unit
): CubicCurve {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CubicCurve(startX, startY, controlX1, controlY1, controlX2, controlY2, endX, endY)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_Dialog.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.control.Dialog
import javafx.scene.control.DialogEvent
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Dialog.setOnShowing
 */
public inline fun Dialog<*>.onShowing(noinline action: (DialogEvent) -> Unit) {
    return setOnShowing(action)
}

/**
 * @see Dialog.setOnShown
 */
public inline fun Dialog<*>.onShown(noinline action: (DialogEvent) -> Unit) {
    return setOnShown(action)
}

/**
 * @see Dialog.setOnHiding
 */
public inline fun Dialog<*>.onHiding(noinline action: (DialogEvent) -> Unit) {
    return setOnHiding(action)
}

/**
 * @see Dialog.setOnHidden
 */
public inline fun Dialog<*>.onHidden(noinline action: (DialogEvent) -> Unit) {
    return setOnHidden(action)
}

/**
 * @see Dialog.setOnCloseRequest
 */
public inline fun Dialog<*>.onCloseRequest(noinline action: (DialogEvent) -> Unit) {
    return setOnCloseRequest(action)
}


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_TreeTableView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.TreeTableColumn
import javafx.scene.control.TreeTableView
import kotlin.Int
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see TreeTableView.setOnSort
 */
public inline fun <T> TreeTableView<T>.onSort(
    noinline action: (SortEvent<TreeTableView<T>>) ->
    Unit
) {
    return setOnSort(action)
}

/**
 * @see TreeTableView.setOnScrollTo
 */
public inline fun <T> TreeTableView<T>.onScrollTo(noinline action: (ScrollToEvent<Int>) -> Unit) {
    return setOnScrollTo(action)
}

/**
 * @see TreeTableView.setOnScrollToColumn
 */
public inline fun <T> TreeTableView<T>.onScrollToColumn(
    noinline
    action: (ScrollToEvent<TreeTableColumn<T, *>>) -> Unit
) {
    return setOnScrollToColumn(action)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/TabPaneTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.TabPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class TabPaneTest : LayoutsTest<KtfxPane, TabPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = tabPane { }
    override fun KtfxPane.child2() = tabPane()
    override fun KtfxPane.child3() = tabPane { }
}

<|start_filename|>ktfx-commons/src/ktfx/collections/ObservableCollections.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ObservableCollectionsKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.collections

import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.collections.ObservableSet

/**
 * @see kotlin.collections.optimizeReadOnlyList
 */
internal fun <T> ObservableList<T>.optimizeReadOnlyList(): ObservableList<T> = when (size) {
    0 -> emptyObservableList()
    1 -> observableListOf(this[0])
    else -> FXCollections.unmodifiableObservableList(this)
}

/**
 * @see kotlin.collections.optimizeReadOnlySet
 */
internal fun <T> ObservableSet<T>.optimizeReadOnlySet(): ObservableSet<T> = when (size) {
    0 -> emptyObservableSet()
    1 -> observableSetOf(iterator().next())
    else -> FXCollections.unmodifiableObservableSet(this)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/dialogs/InputDialogsTest.kt<|end_filename|>
package ktfx.dialogs

import com.hendraanggrian.ktfx.test.DialogShowingTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class InputDialogsTest : DialogShowingTest() {

    @Test
    fun inputDialog() {
        interact {
            assertEquals("Awesome input", inputDialog("Input dialog", sampleGraphic, "Awful input") {
                closeOnShow(this)
                assertEquals("Input dialog", headerText)
                assertEquals(sampleGraphic, graphic)
                assertEquals("Awful input", defaultValue)
                editor.text = "Awesome input"
            }.get())
            assertEquals("Awesome input", inputDialog("Awful input") {
                closeOnShow(this)
                assertEquals("Awful input", defaultValue)
                editor.text = "Awesome input"
            }.get())
        }
    }
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/RangeSliderTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.RangeSlider
import kotlin.test.assertEquals

class RangeSliderTest : LayoutsTest<KtfxPane, RangeSlider>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = rangeSlider { }
    override fun KtfxPane.child2() = rangeSlider()
    override fun KtfxPane.child3() = rangeSlider { }

    override fun RangeSlider.testDefaultValues() {
        assertEquals(0.0, min)
        assertEquals(1.0, max)
        assertEquals(0.25, lowValue)
        assertEquals(0.75, highValue)
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_Rating.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.Rating
import kotlin.Int
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [Rating] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.rating(max: Int = 5, rating: Int = -1): Rating = rating(
    max = max,
    rating =
    rating
) { }

/**
 * Create a [Rating] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun rating(
    max: Int = 5,
    rating: Int = -1,
    configuration: (@KtfxLayoutDslMarker Rating).() -> Unit
): Rating {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Rating(max, rating)
    child.configuration()
    return child
}

/**
 * Add a [Rating] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.rating(
    max: Int = 5,
    rating: Int = -1,
    configuration: (@KtfxLayoutDslMarker Rating).() -> Unit
): Rating {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Rating(max, rating)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Rating].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledRating(
    max: Int = 5,
    rating: Int = -1,
    vararg styleClass: String,
    id: String? = null
): Rating = styledRating(max = max, rating = rating, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [Rating] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledRating(
    max: Int = 5,
    rating: Int = -1,
    vararg styleClass: String,
    id: String? = null
): Rating = styledRating(max = max, rating = rating, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [Rating] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledRating(
    max: Int = 5,
    rating: Int = -1,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Rating).() -> Unit
): Rating {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Rating(max, rating)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Rating] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledRating(
    max: Int = 5,
    rating: Int = -1,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Rating).() -> Unit
): Rating {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Rating(max, rating)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/text/GlyphFontTest.kt<|end_filename|>
package ktfx.controlsfx.text

import com.hendraanggrian.ktfx.test.initToolkit
import org.controlsfx.glyphfont.FontAwesome
import org.controlsfx.glyphfont.GlyphFontRegistry
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

class GlyphFontTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun glyph() {
        val glyphFromChar = FontAwesome() glyph 'A'
        assertEquals("A", glyphFromChar.text)

        val glyphFromString = FontAwesome() glyph "A"
        assertEquals("A", glyphFromString.text)

        val glyphFromEnum = FontAwesome() glyph FontAwesome.Glyph.ADJUST
        assertEquals("\uF042", glyphFromEnum.text)
    }

    @Test
    fun register() {
        val glyphFont = FontAwesome()
        glyphFont.register()
        assertEquals(glyphFont, GlyphFontRegistry.font(glyphFont.name))
    }
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_ListView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.control.ListView
import javafx.scene.control.ScrollToEvent
import kotlin.Int
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see ListView.setOnEditStart
 */
public inline fun <T> ListView<T>.onEditStart(noinline action: (ListView.EditEvent<T>) -> Unit) {
    return setOnEditStart(action)
}

/**
 * @see ListView.setOnEditCommit
 */
public inline fun <T> ListView<T>.onEditCommit(noinline action: (ListView.EditEvent<T>) -> Unit) {
    return setOnEditCommit(action)
}

/**
 * @see ListView.setOnEditCancel
 */
public inline fun <T> ListView<T>.onEditCancel(noinline action: (ListView.EditEvent<T>) -> Unit) {
    return setOnEditCancel(action)
}

/**
 * @see ListView.setOnScrollTo
 */
public inline fun <T> ListView<T>.onScrollTo(noinline action: (ScrollToEvent<Int>) -> Unit) {
    return setOnScrollTo(action)
}


<|start_filename|>testing/listeners-coroutines-jfoenix/src/com/jfoenix/controls/BaseJFXDialogTest.kt<|end_filename|>
package ktfx.jfoenix.test

import com.hendraanggrian.ktfx.test.initToolkit
import com.jfoenix.controls.JFXDialog
import com.jfoenix.controls.events.JFXDialogEvent
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseJFXDialogTest {
    private lateinit var dialog: JFXDialog

    abstract fun JFXDialog.callOnDialogClosed(action: (JFXDialogEvent) -> Unit)
    abstract fun JFXDialog.callOnDialogOpened(action: (JFXDialogEvent) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        dialog = JFXDialog()
    }

    @Test
    fun onDialogClosed() {
        dialog.callOnDialogClosed { assertEquals(JFXDialogEvent.CLOSED, it.eventType) }
        dialog.onDialogClosed.handle(JFXDialogEvent(JFXDialogEvent.CLOSED))
    }

    @Test
    fun onDialogOpened() {
        dialog.callOnDialogOpened { assertEquals(JFXDialogEvent.OPENED, it.eventType) }
        dialog.onDialogOpened.handle(JFXDialogEvent(JFXDialogEvent.OPENED))
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_CustomPasswordField.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.textfield.CustomPasswordField
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [CustomPasswordField] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.customPasswordField(): CustomPasswordField = customPasswordField() { }

/**
 * Create a [CustomPasswordField] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun customPasswordField(
    configuration: (
        @KtfxLayoutDslMarker
        CustomPasswordField
    ).() -> Unit
): CustomPasswordField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomPasswordField()
    child.configuration()
    return child
}

/**
 * Add a [CustomPasswordField] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.customPasswordField(
    configuration: (
        @KtfxLayoutDslMarker
        CustomPasswordField
    ).() -> Unit
): CustomPasswordField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomPasswordField()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [CustomPasswordField].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledCustomPasswordField(vararg styleClass: String, id: String? = null):
    CustomPasswordField = styledCustomPasswordField(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [CustomPasswordField] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledCustomPasswordField(vararg styleClass: String, id: String? = null):
    CustomPasswordField = styledCustomPasswordField(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [CustomPasswordField] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledCustomPasswordField(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker CustomPasswordField).() -> Unit
): CustomPasswordField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomPasswordField()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [CustomPasswordField] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledCustomPasswordField(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker CustomPasswordField).() -> Unit
): CustomPasswordField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomPasswordField()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/src/ktfx/controls/Geometry.kt<|end_filename|>
package ktfx.controls

import javafx.geometry.HPos
import javafx.geometry.Orientation
import javafx.geometry.Pos
import javafx.geometry.Side
import javafx.geometry.VPos

/** Represents positioning on the top vertically and on the left horizontally. */
val TOP_LEFT: Pos = Pos.TOP_LEFT

/** Represents positioning on the top vertically and on the center horizontally. */
val TOP: Pos = Pos.TOP_CENTER

/** Represents positioning on the top vertically and on the right horizontally. */
val TOP_RIGHT: Pos = Pos.TOP_RIGHT

/** Represents positioning on the center vertically and on the left horizontally. */
val LEFT: Pos = Pos.CENTER_LEFT

/** Represents positioning on the center both vertically and horizontally. */
val CENTER: Pos = Pos.CENTER

/** Represents positioning on the center vertically and on the right horizontally. */
val RIGHT: Pos = Pos.CENTER_RIGHT

/** Represents positioning on the bottom vertically and on the left horizontally. */
val BOTTOM_LEFT: Pos = Pos.BOTTOM_LEFT

/** Represents positioning on the bottom vertically and on the center horizontally. */
val BOTTOM: Pos = Pos.BOTTOM_CENTER

/** Represents positioning on the bottom vertically and on the right horizontally. */
val BOTTOM_RIGHT: Pos = Pos.BOTTOM_RIGHT

/** Represents positioning on the baseline vertically and on the left horizontally. */
val BASELINE_LEFT: Pos = Pos.BASELINE_LEFT

/** Represents positioning on the baseline vertically and on the center horizontally. */
val BASELINE: Pos = Pos.BASELINE_CENTER

/** Represents positioning on the baseline vertically and on the right horizontally. */
val BASELINE_RIGHT: Pos = Pos.BASELINE_RIGHT

/** Indicates left horizontal position. */
val H_LEFT: HPos = HPos.LEFT

/** Indicates centered horizontal position. */
val H_CENTER: HPos = HPos.CENTER

/** Indicates right horizontal position. */
val H_RIGHT: HPos = HPos.RIGHT

/** Indicates top vertical position. */
val V_TOP: VPos = VPos.TOP

/** Indicates centered vertical position. */
val V_CENTER: VPos = VPos.CENTER

/** Indicates baseline vertical position. */
val V_BASELINE: VPos = VPos.BASELINE

/** Indicates bottom vertical position. */
val V_BOTTOM: VPos = VPos.BOTTOM

/** The horizontal (right <-> left) orientation. */
val HORIZONTAL: Orientation = Orientation.HORIZONTAL

/** The vertical (top <-> bottom) orientation. */
val VERTICAL: Orientation = Orientation.VERTICAL

/** Represents top side of a rectangle. */
val SIDE_TOP: Side = Side.TOP

/** Represents bottom side of a rectangle. */
val SIDE_BOTTOM: Side = Side.BOTTOM

/** Represents left side of a rectangle. */
val SIDE_LEFT: Side = Side.LEFT

/** Represents right side of a rectangle. */
val SIDE_RIGHT: Side = Side.RIGHT


<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseTabTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.Event
import javafx.scene.control.Tab
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseTabTest {
    private lateinit var tab: Tab

    abstract fun Tab.callOnSelectionChanged(action: (Event) -> Unit)
    abstract fun Tab.callOnClosed(action: (Event) -> Unit)
    abstract fun Tab.callOnCloseRequest(action: (Event) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        tab = Tab()
    }

    @Test
    fun onSelectionChanged() {
        tab.callOnSelectionChanged {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        tab.onSelectionChanged.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onClosed() {
        tab.callOnClosed {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        tab.onClosed.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onCloseRequest() {
        tab.callOnCloseRequest {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        tab.onCloseRequest.handle(Event(this, FakeEventTarget, Event.ANY))
    }
}

<|start_filename|>rulesets/non-commons/src/com/hendraanggrian/ktfx/rules/PredefinedPackageRule.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.pinterest.ktlint.core.Rule
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.psi.KtPackageDirective
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes

/** Classes and extension functions may only be deployed to single pre-defined package. */
class PredefinedPackageRule : Rule("predefined-package") {
    private companion object {
        val PREDEFINED_PACKAGES = setOf(
            "ktfx.coroutines",
            "ktfx.layouts",
            "ktfx.listeners",
            "ktfx.internal",
            "ktfx.controlsfx.coroutines",
            "ktfx.controlsfx.layouts",
            "ktfx.controlsfx.listeners",
            "ktfx.jfoenix.coroutines",
            "ktfx.jfoenix.layouts",
            "ktfx.jfoenix.listeners"
        )
    }

    private var currentPackageName: String? = null

    override fun visit(node: ASTNode, autoCorrect: Boolean, emit: (Int, String, Boolean) -> Unit) {
        if (node.elementType != KtStubElementTypes.PACKAGE_DIRECTIVE) {
            return
        }
        val ktPackageDirective = node.getPsi(KtPackageDirective::class.java)
        val packageName = ktPackageDirective.qualifiedName

        // to ensure single package
        if (currentPackageName == null) {
            currentPackageName = packageName
        }

        when {
            packageName != currentPackageName ->
                emit(ktPackageDirective.packageNameExpression!!.startOffset, "Non-single package detected.", false)
            packageName !in PREDEFINED_PACKAGES ->
                emit(ktPackageDirective.packageNameExpression!!.startOffset, "Illegal package name.", false)
        }
    }
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/InfoOverlayTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.InfoOverlay
import kotlin.test.assertNull

class InfoOverlayTest : LayoutsTest<KtfxPane, InfoOverlay>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = infoOverlay { }
    override fun KtfxPane.child2() = infoOverlay()
    override fun KtfxPane.child3() = infoOverlay { }

    override fun InfoOverlay.testDefaultValues() {
        assertNull(content)
        assertNull(text)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/dialogs/Alerts.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.dialogs

import javafx.scene.Node
import javafx.scene.control.Alert
import javafx.scene.control.Alert.AlertType
import javafx.scene.control.ButtonType
import javafx.scene.image.ImageView
import java.util.Optional

/**
 * Show an alert with title and graphic.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param content alert message.
 * @param buttonTypes alert buttons.
 * @param alertAction custom dialog action.
 * @return selected alert button.
 */
fun alert(
    title: String? = null,
    graphic: Node? = null,
    content: String = "",
    vararg buttonTypes: ButtonType,
    alertAction: (Alert.() -> Unit)? = null
): Optional<ButtonType> = Alert(AlertType.NONE, content, *buttonTypes).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    alertAction?.invoke(dialog)
}.showAndWait()

/**
 * Show an alert.
 * @param content alert message.
 * @param buttonTypes alert buttons.
 * @param alertAction custom dialog action.
 * @return selected alert button.
 */
inline fun alert(
    content: String = "",
    vararg buttonTypes: ButtonType,
    noinline alertAction: (Alert.() -> Unit)? = null
): Optional<ButtonType> = alert(null, null, content, *buttonTypes, alertAction = alertAction)

/**
 * Show an information alert with title and graphic.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param content alert message.
 * @param buttonTypes alert buttons.
 * @param alertAction custom dialog action.
 * @return selected alert button.
 */
fun infoAlert(
    title: String? = null,
    graphic: Node? = null,
    content: String = "",
    vararg buttonTypes: ButtonType,
    alertAction: (Alert.() -> Unit)? = null
): Optional<ButtonType> = Alert(AlertType.INFORMATION, content, *buttonTypes).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    alertAction?.invoke(dialog)
}.showAndWait()

/**
 * Show an information alert.
 * @param content alert message.
 * @param buttonTypes alert buttons.
 * @param alertAction custom dialog action.
 * @return selected alert button.
 */
inline fun infoAlert(
    content: String = "",
    vararg buttonTypes: ButtonType,
    noinline alertAction: (Alert.() -> Unit)? = null
): Optional<ButtonType> = infoAlert(null, null, content, *buttonTypes, alertAction = alertAction)

/**
 * Show a warning alert with title and graphic.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param content alert message.
 * @param buttonTypes alert buttons.
 * @param alertAction custom dialog action.
 * @return selected alert button.
 */
fun warningAlert(
    title: String? = null,
    graphic: Node? = null,
    content: String = "",
    vararg buttonTypes: ButtonType,
    alertAction: (Alert.() -> Unit)? = null
): Optional<ButtonType> = Alert(AlertType.WARNING, content, *buttonTypes).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    alertAction?.invoke(dialog)
}.showAndWait()

/**
 * Show a warning alert.
 * @param content alert message.
 * @param buttonTypes alert buttons.
 * @param alertAction custom dialog action.
 * @return selected alert button.
 */
inline fun warningAlert(
    content: String = "",
    vararg buttonTypes: ButtonType,
    noinline alertAction: (Alert.() -> Unit)? = null
): Optional<ButtonType> = warningAlert(null, null, content, *buttonTypes, alertAction = alertAction)

/**
 * Show a confirmation alert with title and graphic.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param content alert message.
 * @param buttonTypes alert buttons.
 * @param alertAction custom dialog action.
 * @return selected alert button.
 */
fun confirmAlert(
    title: String? = null,
    graphic: Node? = null,
    content: String = "",
    vararg buttonTypes: ButtonType,
    alertAction: (Alert.() -> Unit)? = null
): Optional<ButtonType> = Alert(AlertType.CONFIRMATION, content, *buttonTypes).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    alertAction?.invoke(dialog)
}.showAndWait()

/**
 * Show a confirmation alert.
 * @param content alert message.
 * @param buttonTypes alert buttons.
 * @param alertAction custom dialog action.
 * @return selected alert button.
 */
inline fun confirmAlert(
    content: String = "",
    vararg buttonTypes: ButtonType,
    noinline alertAction: (Alert.() -> Unit)? = null
): Optional<ButtonType> = confirmAlert(null, null, content, *buttonTypes, alertAction = alertAction)

/**
 * Show an error alert with title and graphic.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param content alert message.
 * @param buttonTypes alert buttons.
 * @param alertAction custom dialog action.
 * @return selected alert button.
 */
fun errorAlert(
    title: String? = null,
    graphic: Node? = null,
    content: String = "",
    vararg buttonTypes: ButtonType,
    alertAction: (Alert.() -> Unit)? = null
): Optional<ButtonType> = Alert(AlertType.ERROR, content, *buttonTypes).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    alertAction?.invoke(dialog)
}.showAndWait()

/**
 * Show an error alert.
 * @param content alert message.
 * @param buttonTypes alert buttons.
 * @param alertAction custom dialog action.
 * @return selected alert button.
 */
inline fun errorAlert(
    content: String = "",
    vararg buttonTypes: ButtonType,
    noinline alertAction: (Alert.() -> Unit)? = null
): Optional<ButtonType> = errorAlert(null, null, content, *buttonTypes, alertAction = alertAction)


<|start_filename|>ktfx-commons/tests/src/ktfx/dialogs/AlertsTest.kt<|end_filename|>
package ktfx.dialogs

import javafx.scene.control.ButtonType
import com.hendraanggrian.ktfx.test.DialogShowingTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class AlertsTest : DialogShowingTest() {

    @Test
    fun alert() {
        interact {
            assertEquals(ButtonType.YES, alert("Alert title", sampleGraphic, "Message", ButtonType.YES) {
                closeOnShow(this)
                assertEquals("Alert title", headerText)
                assertEquals(sampleGraphic, graphic)
                assertEquals("Message", contentText)
            }.get())
            assertEquals(ButtonType.FINISH, alert("Message", ButtonType.FINISH) {
                closeOnShow(this)
                assertEquals("Message", contentText)
            }.get())
        }
    }

    @Test
    fun infoAlert() {
        interact {
            assertEquals(ButtonType.OK, infoAlert("Info title", sampleGraphic, "Message") {
                closeOnShow(this)
                assertEquals("Info title", headerText)
                assertEquals(sampleGraphic, graphic)
                assertEquals("Message", contentText)
            }.get())
            assertEquals(ButtonType.OK, infoAlert("Message") {
                closeOnShow(this)
                assertEquals("Message", contentText)
            }.get())
        }
    }

    @Test
    fun warningAlert() {
        interact {
            assertEquals(ButtonType.OK, infoAlert("Warning title", sampleGraphic, "Message") {
                closeOnShow(this)
                assertEquals("Warning title", headerText)
                assertEquals(sampleGraphic, graphic)
                assertEquals("Message", contentText)
            }.get())
            assertEquals(ButtonType.OK, infoAlert("Message") {
                closeOnShow(this)
                assertEquals("Message", contentText)
            }.get())
        }
    }

    @Test
    fun confirmAlert() {
        interact {
            assertEquals(ButtonType.OK, confirmAlert("Confirm title", sampleGraphic, "Message") {
                closeOnShow(this)
                assertEquals("Confirm title", headerText)
                assertEquals(sampleGraphic, graphic)
                assertEquals("Message", contentText)
            }.get())
            assertEquals(ButtonType.OK, confirmAlert("Message") {
                closeOnShow(this)
                assertEquals("Message", contentText)
            }.get())
        }
    }

    @Test
    fun errorAlert() {
        interact {
            assertEquals(ButtonType.OK, errorAlert("Error title", sampleGraphic, "Message") {
                closeOnShow(this)
                assertEquals("Error title", headerText)
                assertEquals(sampleGraphic, graphic)
                assertEquals("Message", contentText)
            }.get())
            assertEquals(ButtonType.OK, errorAlert("Message") {
                closeOnShow(this)
                assertEquals("Message", contentText)
            }.get())
        }
    }
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXRipplerTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXRippler
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXRipplerTest : LayoutsTest<KtfxPane, JFXRippler>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxRippler { }
    override fun KtfxPane.child2() = jfxRippler()
    override fun KtfxPane.child3() = jfxRippler { }
}

<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/Platform.kt<|end_filename|>
@file:JvmName("ControlsFxPlatformKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx

import org.controlsfx.tools.Platform

/** Returns true if this is running on Windows OS. */
inline fun isPlatformWindows(): Boolean = Platform.getCurrent() == Platform.WINDOWS

/** Returns true if this is running on Mac OS. */
inline fun isPlatformOSX(): Boolean = Platform.getCurrent() == Platform.OSX

/** Returns true if this is running on Unix OS. */
inline fun isPlatformUnix(): Boolean = Platform.getCurrent() == Platform.UNIX


<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/TreeTableColumnTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.control.TreeTableColumn
import com.hendraanggrian.ktfx.test.BaseTreeTableColumnTest

class TreeTableColumnTest : BaseTreeTableColumnTest() {

    override fun <S, T> TreeTableColumn<S, T>.callOnEditStart(action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditStart(action)

    override fun <S, T> TreeTableColumn<S, T>.callOnEditCommit(action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditCommit(action)

    override fun <S, T> TreeTableColumn<S, T>.callOnEditCancel(action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditCancel(action)
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/PolygonTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.shape.Polygon
import com.hendraanggrian.ktfx.test.LayoutsTest

class PolygonTest : LayoutsTest<KtfxPane, Polygon>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = polygon { }
    override fun KtfxPane.child2() = polygon()
    override fun KtfxPane.child3() = polygon { }

    override fun Polygon.testDefaultValues() {
        assertThat(points).isEmpty()
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/BaseNodeTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import com.google.common.truth.Truth.assertThat
import javafx.scene.Node
import javafx.scene.control.Label
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse

abstract class BaseNodeTest {
    private lateinit var node: Label

    abstract fun Node.callOnDragEntered(action: (DragEvent) -> Unit)
    abstract fun Node.callOnDragExited(action: (DragEvent) -> Unit)
    abstract fun Node.callOnDragOver(action: (DragEvent) -> Unit)
    abstract fun Node.callOnDragDropped(action: (DragEvent) -> Unit)
    abstract fun Node.callOnDragDone(action: (DragEvent) -> Unit)
    abstract fun Node.callOnContextMenuRequested(action: (ContextMenuEvent) -> Unit)
    abstract fun Node.callOnMouseClicked(action: (MouseEvent) -> Unit)
    abstract fun Node.callOnMouseDragged(action: (MouseEvent) -> Unit)
    abstract fun Node.callOnMouseEntered(action: (MouseEvent) -> Unit)
    abstract fun Node.callOnMouseExited(action: (MouseEvent) -> Unit)
    abstract fun Node.callOnMouseMoved(action: (MouseEvent) -> Unit)
    abstract fun Node.callOnMousePressed(action: (MouseEvent) -> Unit)
    abstract fun Node.callOnMouseReleased(action: (MouseEvent) -> Unit)
    abstract fun Node.callOnDragDetected(action: (MouseEvent) -> Unit)
    abstract fun Node.callOnMouseDragOver(action: (MouseDragEvent) -> Unit)
    abstract fun Node.callOnMouseDragReleased(action: (MouseDragEvent) -> Unit)
    abstract fun Node.callOnMouseDragEntered(action: (MouseDragEvent) -> Unit)
    abstract fun Node.callOnMouseDragExited(action: (MouseDragEvent) -> Unit)
    abstract fun Node.callOnScrollStarted(action: (ScrollEvent) -> Unit)
    abstract fun Node.callOnScroll(action: (ScrollEvent) -> Unit)
    abstract fun Node.callOnScrollFinished(action: (ScrollEvent) -> Unit)
    abstract fun Node.callOnRotationStarted(action: (RotateEvent) -> Unit)
    abstract fun Node.callOnRotate(action: (RotateEvent) -> Unit)
    abstract fun Node.callOnRotationFinished(action: (RotateEvent) -> Unit)
    abstract fun Node.callOnZoomStarted(action: (ZoomEvent) -> Unit)
    abstract fun Node.callOnZoom(action: (ZoomEvent) -> Unit)
    abstract fun Node.callOnZoomFinished(action: (ZoomEvent) -> Unit)
    abstract fun Node.callOnSwipeUp(action: (SwipeEvent) -> Unit)
    abstract fun Node.callOnSwipeDown(action: (SwipeEvent) -> Unit)
    abstract fun Node.callOnSwipeLeft(action: (SwipeEvent) -> Unit)
    abstract fun Node.callOnSwipeRight(action: (SwipeEvent) -> Unit)
    abstract fun Node.callOnTouchPressed(action: (TouchEvent) -> Unit)
    abstract fun Node.callOnTouchMoved(action: (TouchEvent) -> Unit)
    abstract fun Node.callOnTouchReleased(action: (TouchEvent) -> Unit)
    abstract fun Node.callOnTouchStationary(action: (TouchEvent) -> Unit)
    abstract fun Node.callOnKeyPressed(action: (KeyEvent) -> Unit)
    abstract fun Node.callOnKeyReleased(action: (KeyEvent) -> Unit)
    abstract fun Node.callOnKeyTyped(action: (KeyEvent) -> Unit)
    abstract fun Node.callOnInputMethodTextChanged(action: (InputMethodEvent) -> Unit)

    @BeforeTest
    fun onCreate() {
        initToolkit()
        node = Label()
    }

    @Test
    fun onDragEntered() {
        node.callOnDragEntered { assertFakeDragEvent(it, DragEvent.DRAG_ENTERED) }
        node.onDragEntered.handle(fakeDragEventOf(DragEvent.DRAG_ENTERED))
    }

    @Test
    fun onDragExited() {
        node.callOnDragExited { assertFakeDragEvent(it, DragEvent.DRAG_EXITED) }
        node.onDragExited.handle(fakeDragEventOf(DragEvent.DRAG_EXITED))
    }

    @Test
    fun onDragOver() {
        node.callOnDragOver { assertFakeDragEvent(it, DragEvent.DRAG_OVER) }
        node.onDragOver.handle(fakeDragEventOf(DragEvent.DRAG_OVER))
    }

    @Test
    fun onDragDropped() {
        node.callOnDragDropped { assertFakeDragEvent(it, DragEvent.DRAG_DROPPED) }
        node.onDragDropped.handle(fakeDragEventOf(DragEvent.DRAG_DROPPED))
    }

    @Test
    fun onDragDone() {
        node.callOnDragDone { assertFakeDragEvent(it, DragEvent.DRAG_DONE) }
        node.onDragDone.handle(fakeDragEventOf(DragEvent.DRAG_DONE))
    }

    @Test
    fun onContextMenuRequested() {
        node.callOnContextMenuRequested {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(ContextMenuEvent.CONTEXT_MENU_REQUESTED, it.eventType)
            assertEquals(0.0, it.x)
            assertEquals(0.0, it.y)
            assertEquals(0.0, it.sceneX)
            assertEquals(0.0, it.sceneY)
            assertFalse(it.isKeyboardTrigger)
            assertEquals(FakePickResult, it.pickResult)
        }
        node.onContextMenuRequested.handle(
            ContextMenuEvent(
                this, FakeEventTarget, ContextMenuEvent.CONTEXT_MENU_REQUESTED,
                0.0, 0.0, 0.0, 0.0,
                false, FakePickResult
            )
        )
    }

    @Test
    fun onMouseClicked() {
        node.callOnMouseClicked { assertFakeMouseEvent(it, MouseEvent.MOUSE_CLICKED) }
        node.onMouseClicked.handle(fakeMouseEventOf(MouseEvent.MOUSE_CLICKED))
    }

    @Test
    fun onMouseDragged() {
        node.callOnMouseDragged { assertFakeMouseEvent(it, MouseEvent.MOUSE_DRAGGED) }
        node.onMouseDragged.handle(fakeMouseEventOf(MouseEvent.MOUSE_DRAGGED))
    }

    @Test
    fun onMouseEntered() {
        node.callOnMouseEntered { assertFakeMouseEvent(it, MouseEvent.MOUSE_ENTERED) }
        node.onMouseEntered.handle(fakeMouseEventOf(MouseEvent.MOUSE_ENTERED))
    }

    @Test
    fun onMouseExited() {
        node.callOnMouseExited { assertFakeMouseEvent(it, MouseEvent.MOUSE_EXITED) }
        node.onMouseExited.handle(fakeMouseEventOf(MouseEvent.MOUSE_EXITED))
    }

    @Test
    fun onMouseMoved() {
        node.callOnMouseMoved { assertFakeMouseEvent(it, MouseEvent.MOUSE_MOVED) }
        node.onMouseMoved.handle(fakeMouseEventOf(MouseEvent.MOUSE_MOVED))
    }

    @Test
    fun onMousePressed() {
        node.callOnMousePressed { assertFakeMouseEvent(it, MouseEvent.MOUSE_PRESSED) }
        node.onMousePressed.handle(fakeMouseEventOf(MouseEvent.MOUSE_PRESSED))
    }

    @Test
    fun onMouseReleased() {
        node.callOnMouseReleased { assertFakeMouseEvent(it, MouseEvent.MOUSE_RELEASED) }
        node.onMouseReleased.handle(fakeMouseEventOf(MouseEvent.MOUSE_RELEASED))
    }

    @Test
    fun onDragDetected() {
        node.callOnDragDetected { assertFakeMouseEvent(it, MouseEvent.DRAG_DETECTED) }
        node.onDragDetected.handle(fakeMouseEventOf(MouseEvent.DRAG_DETECTED))
    }

    @Test
    fun onMouseDragOver() {
        node.callOnMouseDragOver { assertFakeMouseDragEvent(it, MouseDragEvent.MOUSE_DRAG_OVER) }
        node.onMouseDragOver.handle(fakeMouseDragEventOf(MouseDragEvent.MOUSE_DRAG_OVER))
    }

    @Test
    fun onMouseDragReleased() {
        node.callOnMouseDragReleased { assertFakeMouseDragEvent(it, MouseDragEvent.MOUSE_DRAG_RELEASED) }
        node.onMouseDragReleased.handle(fakeMouseDragEventOf(MouseDragEvent.MOUSE_DRAG_RELEASED))
    }

    @Test
    fun onMouseDragEntered() {
        node.callOnMouseDragEntered { assertFakeMouseDragEvent(it, MouseDragEvent.MOUSE_DRAG_ENTERED) }
        node.onMouseDragEntered.handle(fakeMouseDragEventOf(MouseDragEvent.MOUSE_DRAG_ENTERED))
    }

    @Test
    fun onMouseDragExited() {
        node.callOnMouseDragExited { assertFakeMouseDragEvent(it, MouseDragEvent.MOUSE_DRAG_EXITED) }
        node.onMouseDragExited.handle(fakeMouseDragEventOf(MouseDragEvent.MOUSE_DRAG_EXITED))
    }

    @Test
    fun onScrollStarted() {
        node.callOnScrollStarted { assertFakeScrollEvent(it, ScrollEvent.SCROLL_STARTED) }
        node.onScrollStarted.handle(fakeScrollEventOf(ScrollEvent.SCROLL_STARTED))
    }

    @Test
    fun onScroll() {
        node.callOnScroll { assertFakeScrollEvent(it, ScrollEvent.SCROLL) }
        node.onScroll.handle(fakeScrollEventOf(ScrollEvent.SCROLL))
    }

    @Test
    fun onScrollFinished() {
        node.callOnScrollFinished { assertFakeScrollEvent(it, ScrollEvent.SCROLL_FINISHED) }
        node.onScrollFinished.handle(fakeScrollEventOf(ScrollEvent.SCROLL_FINISHED))
    }

    @Test
    fun onRotateStarted() {
        node.callOnRotationStarted { assertFakeRotateEvent(it, RotateEvent.ROTATION_STARTED) }
        node.onRotationStarted.handle(fakeRotateEventOf(RotateEvent.ROTATION_STARTED))
    }

    @Test
    fun onRotate() {
        node.callOnRotate { assertFakeRotateEvent(it, RotateEvent.ROTATE) }
        node.onRotate.handle(fakeRotateEventOf(RotateEvent.ROTATE))
    }

    @Test
    fun onRotateFinished() {
        node.callOnRotationFinished { assertFakeRotateEvent(it, RotateEvent.ROTATION_FINISHED) }
        node.onRotationFinished.handle(fakeRotateEventOf(RotateEvent.ROTATION_FINISHED))
    }

    @Test
    fun onZoomStarted() {
        node.callOnZoomStarted { assertFakeZoomEvent(it, ZoomEvent.ZOOM_STARTED) }
        node.onZoomStarted.handle(fakeZoomEventOf(ZoomEvent.ZOOM_STARTED))
    }

    @Test
    fun onZoom() {
        node.callOnZoom { assertFakeZoomEvent(it, ZoomEvent.ZOOM) }
        node.onZoom.handle(fakeZoomEventOf(ZoomEvent.ZOOM))
    }

    @Test
    fun onZoomFinished() {
        node.callOnZoomFinished { assertFakeZoomEvent(it, ZoomEvent.ZOOM_FINISHED) }
        node.onZoomFinished.handle(fakeZoomEventOf(ZoomEvent.ZOOM_FINISHED))
    }

    @Test
    fun onSwipeUp() {
        node.callOnSwipeUp { assertFakeSwipeEvent(it, SwipeEvent.SWIPE_UP) }
        node.onSwipeUp.handle(fakeSwipeEventOf(SwipeEvent.SWIPE_UP))
    }

    @Test
    fun onSwipeDown() {
        node.callOnSwipeDown { assertFakeSwipeEvent(it, SwipeEvent.SWIPE_DOWN) }
        node.onSwipeDown.handle(fakeSwipeEventOf(SwipeEvent.SWIPE_DOWN))
    }

    @Test
    fun onSwipeRight() {
        node.callOnSwipeRight { assertFakeSwipeEvent(it, SwipeEvent.SWIPE_RIGHT) }
        node.onSwipeRight.handle(fakeSwipeEventOf(SwipeEvent.SWIPE_RIGHT))
    }

    @Test
    fun onSwipeLeft() {
        node.callOnSwipeLeft { assertFakeSwipeEvent(it, SwipeEvent.SWIPE_LEFT) }
        node.onSwipeLeft.handle(fakeSwipeEventOf(SwipeEvent.SWIPE_LEFT))
    }

    @Test
    fun onTouchPressed() {
        node.callOnTouchPressed { assertFakeTouchEvent(it, TouchEvent.TOUCH_PRESSED) }
        node.onTouchPressed.handle(fakeTouchEventOf(TouchEvent.TOUCH_PRESSED))
    }

    @Test
    fun onTouchMoved() {
        node.callOnTouchMoved { assertFakeTouchEvent(it, TouchEvent.TOUCH_MOVED) }
        node.onTouchMoved.handle(fakeTouchEventOf(TouchEvent.TOUCH_MOVED))
    }

    @Test
    fun onTouchReleased() {
        node.callOnTouchReleased { assertFakeTouchEvent(it, TouchEvent.TOUCH_RELEASED) }
        node.onTouchReleased.handle(fakeTouchEventOf(TouchEvent.TOUCH_RELEASED))
    }

    @Test
    fun onTouchStationary() {
        node.callOnTouchStationary { assertFakeTouchEvent(it, TouchEvent.TOUCH_STATIONARY) }
        node.onTouchStationary.handle(fakeTouchEventOf(TouchEvent.TOUCH_STATIONARY))
    }

    @Test
    fun onKeyPressed() {
        node.callOnKeyPressed { assertFakeKeyEvent(it, KeyEvent.KEY_PRESSED) }
        node.onKeyPressed.handle(fakeKeyEventOf(KeyEvent.KEY_PRESSED))
    }

    @Test
    fun onKeyReleased() {
        node.callOnKeyReleased { assertFakeKeyEvent(it, KeyEvent.KEY_RELEASED) }
        node.onKeyReleased.handle(fakeKeyEventOf(KeyEvent.KEY_RELEASED))
    }

    @Test
    fun onKeyTyped() {
        node.callOnKeyTyped { assertFakeKeyEvent(it, KeyEvent.KEY_TYPED) }
        node.onKeyTyped.handle(fakeKeyEventOf(KeyEvent.KEY_TYPED))
    }

    @Test
    fun onInputMethodTextChanged() {
        node.callOnInputMethodTextChanged {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, it.eventType)
            assertThat(it.composed).isEmpty()
            assertEquals("Hello world", it.committed)
            assertEquals(0, it.caretPosition)
        }
        node.onInputMethodTextChanged.handle(
            InputMethodEvent(
                this, FakeEventTarget, InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                listOf(), "Hello world", 0
            )
        )
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_PlusMinusSlider.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.PlusMinusSlider
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [PlusMinusSlider] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.plusMinusSlider(): PlusMinusSlider = plusMinusSlider() { }

/**
 * Create a [PlusMinusSlider] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun plusMinusSlider(configuration: (@KtfxLayoutDslMarker PlusMinusSlider).() -> Unit):
    PlusMinusSlider {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PlusMinusSlider()
    child.configuration()
    return child
}

/**
 * Add a [PlusMinusSlider] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.plusMinusSlider(
    configuration: (
        @KtfxLayoutDslMarker
        PlusMinusSlider
    ).() -> Unit
): PlusMinusSlider {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PlusMinusSlider()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [PlusMinusSlider].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledPlusMinusSlider(vararg styleClass: String, id: String? = null): PlusMinusSlider =
    styledPlusMinusSlider(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [PlusMinusSlider] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledPlusMinusSlider(vararg styleClass: String, id: String? = null):
    PlusMinusSlider = styledPlusMinusSlider(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [PlusMinusSlider] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledPlusMinusSlider(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker PlusMinusSlider).() -> Unit
): PlusMinusSlider {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PlusMinusSlider()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [PlusMinusSlider] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledPlusMinusSlider(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker PlusMinusSlider).() -> Unit
): PlusMinusSlider {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PlusMinusSlider()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>sample/build.gradle.kts<|end_filename|>
plugins {
    javafx
    kotlin("jvm")
    application
}

javafx {
    modules("javafx.controls")
}

application {
    mainClass.set("com.example.CalculatorApp")
}

sourceSets {
    main {
        java.srcDir("src")
    }
}

dependencies {
    implementation(project(":ktfx"))
    implementation(project(":thirdparty:controlsfx"))
    implementation(project(":thirdparty:jfoenix"))
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_ContextMenu.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.ActionEvent
import javafx.scene.control.ContextMenu
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see ContextMenu.setOnAction
 */
public inline fun ContextMenu.onAction(noinline action: (ActionEvent) -> Unit) {
    return setOnAction(action)
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXTextFieldTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTextField
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class JFXTextFieldTest : LayoutsTest<KtfxPane, JFXTextField>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxTextField { }
    override fun KtfxPane.child2() = jfxTextField()
    override fun KtfxPane.child3() = jfxTextField { }

    override fun JFXTextField.testDefaultValues() {
        assertNull(text)
    }
}

<|start_filename|>testing/listeners-coroutines-jfoenix/src/com/jfoenix/controls/BaseJFXDrawerTest.kt<|end_filename|>
package ktfx.jfoenix.test

import com.hendraanggrian.ktfx.test.initToolkit
import com.jfoenix.controls.JFXDrawer
import com.jfoenix.controls.events.JFXDrawerEvent
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseJFXDrawerTest {
    private lateinit var drawer: JFXDrawer

    abstract fun JFXDrawer.callOnDrawerClosed(action: (JFXDrawerEvent) -> Unit)
    abstract fun JFXDrawer.callOnDrawerClosing(action: (JFXDrawerEvent) -> Unit)
    abstract fun JFXDrawer.callOnDrawerOpened(action: (JFXDrawerEvent) -> Unit)
    abstract fun JFXDrawer.callOnDrawerOpening(action: (JFXDrawerEvent) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        drawer = JFXDrawer()
    }

    @Test
    fun onDrawerClosed() {
        drawer.callOnDrawerClosed { assertEquals(JFXDrawerEvent.CLOSED, it.eventType) }
        drawer.onDrawerClosed.handle(JFXDrawerEvent(JFXDrawerEvent.CLOSED))
    }

    @Test
    fun onDrawerClosing() {
        drawer.callOnDrawerClosing { assertEquals(JFXDrawerEvent.CLOSING, it.eventType) }
        drawer.onDrawerClosing.handle(JFXDrawerEvent(JFXDrawerEvent.CLOSING))
    }

    @Test
    fun onDrawerOpened() {
        drawer.callOnDrawerOpened { assertEquals(JFXDrawerEvent.OPENED, it.eventType) }
        drawer.onDrawerOpened.handle(JFXDrawerEvent(JFXDrawerEvent.OPENED))
    }

    @Test
    fun onDrawerOpening() {
        drawer.callOnDrawerOpening { assertEquals(JFXDrawerEvent.OPENING, it.eventType) }
        drawer.onDrawerOpening.handle(JFXDrawerEvent(JFXDrawerEvent.OPENING))
    }
}

<|start_filename|>thirdparty/controlsfx-coroutines/tests/src/org/controlsfx/control/NotificationPaneTest.kt<|end_filename|>
package ktfx.controlsfx.coroutines

import javafx.event.Event
import kotlinx.coroutines.Dispatchers
import ktfx.controlsfx.test.BaseNotificationPaneTest
import org.controlsfx.control.NotificationPane

class NotificationPaneTest : BaseNotificationPaneTest() {

    override fun NotificationPane.callOnShowing(action: (Event) -> Unit) =
        onShowing(Dispatchers.Unconfined) { action(it) }

    override fun NotificationPane.callOnShown(action: (Event) -> Unit) =
        onShown(Dispatchers.Unconfined) { action(it) }

    override fun NotificationPane.callOnHiding(action: (Event) -> Unit) =
        onHiding(Dispatchers.Unconfined) { action(it) }

    override fun NotificationPane.callOnHidden(action: (Event) -> Unit) =
        onHidden(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_ScrollPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.ScrollPane
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [ScrollPane] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.scrollPane(content: Node? = null): ScrollPane = scrollPane(content = content) { }

/**
 * Create a [ScrollPane] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun scrollPane(
    content: Node? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        KtfxScrollPane
    ).() -> Unit
): ScrollPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxScrollPane(content)
    child.configuration()
    return child
}

/**
 * Add a [ScrollPane] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.scrollPane(
    content: Node? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        KtfxScrollPane
    ).() -> Unit
): ScrollPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxScrollPane(content)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [ScrollPane].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledScrollPane(
    content: Node? = null,
    vararg styleClass: String,
    id: String? = null
): ScrollPane = styledScrollPane(content = content, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [ScrollPane] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledScrollPane(
    content: Node? = null,
    vararg styleClass: String,
    id: String? = null
): ScrollPane = styledScrollPane(content = content, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [ScrollPane] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledScrollPane(
    content: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxScrollPane).() -> Unit
): ScrollPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxScrollPane(content)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [ScrollPane] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledScrollPane(
    content: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxScrollPane).() -> Unit
): ScrollPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxScrollPane(content)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/dialogs/SelectorsTest.kt<|end_filename|>
package ktfx.dialogs

import com.hendraanggrian.ktfx.test.DialogShowingTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class SelectorsTest : DialogShowingTest() {

    @Test
    fun selector() {
        interact {
            assertEquals(
                "Jump off bridge",
                selector<String>(
                    "Selector", sampleGraphic,
                    listOf("Jump off bridge", "Live a happy life"), "Live a happy life"
                ) {
                    closeOnShow(this)
                    assertEquals("Selector", headerText)
                    assertEquals(sampleGraphic, graphic)
                    assertEquals("Live a happy life", defaultChoice)
                    selectedItem = "Jump off bridge"
                }.get()
            )
            assertEquals(
                "Jump off bridge",
                selector<String>(listOf("Jump off bridge", "Live a happy life"), "Live a happy life") {
                    closeOnShow(this)
                    assertEquals("Live a happy life", defaultChoice)
                    selectedItem = "Jump off bridge"
                }.get()
            )
            assertEquals(
                "Jump off bridge",
                selector<String>(
                    "Selector", sampleGraphic,
                    "Jump off bridge", "Live a happy life", prefill = "Live a happy life"
                ) {
                    closeOnShow(this)
                    assertEquals("Selector", headerText)
                    assertEquals(sampleGraphic, graphic)
                    assertEquals("Live a happy life", defaultChoice)
                    selectedItem = "Jump off bridge"
                }.get()
            )
            assertEquals(
                "Jump off bridge",
                selector("Jump off bridge", "Live a happy life", prefill = "Live a happy life") {
                    closeOnShow(this)
                    selectedItem = "Jump off bridge"
                }.get()
            )
        }
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/web/WebViewTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.web.WebView
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.Ignore

/** Error on [child1], [child2] and [child3] because creating [WebView] must be in FX thread. */
@Ignore
class WebViewTest : LayoutsTest<KtfxPane, WebView>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = webView { }
    override fun KtfxPane.child2() = webView()
    override fun KtfxPane.child3() = webView { }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/NumberValueBindingInteger.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("NumberValueBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.DoubleBinding
import javafx.beans.binding.FloatBinding
import javafx.beans.binding.IntegerBinding
import javafx.beans.binding.IntegerExpression
import javafx.beans.binding.LongBinding
import javafx.beans.value.ObservableIntegerValue

/** @see IntegerExpression.negate */
inline operator fun ObservableIntegerValue.unaryMinus(): IntegerBinding = Bindings.negate(this) as IntegerBinding

/** @see IntegerExpression.add */
inline operator fun ObservableIntegerValue.plus(other: Double): DoubleBinding = Bindings.add(this, other)

/** @see IntegerExpression.add */
inline operator fun Double.plus(other: ObservableIntegerValue): DoubleBinding = Bindings.add(this, other)

/** @see IntegerExpression.add */
inline operator fun ObservableIntegerValue.plus(other: Float): FloatBinding = Bindings.add(this, other) as FloatBinding

/** @see IntegerExpression.add */
inline operator fun Float.plus(other: ObservableIntegerValue): FloatBinding = Bindings.add(this, other) as FloatBinding

/** @see IntegerExpression.add */
inline operator fun ObservableIntegerValue.plus(other: Long): LongBinding = Bindings.add(this, other) as LongBinding

/** @see IntegerExpression.add */
inline operator fun Long.plus(other: ObservableIntegerValue): LongBinding = Bindings.add(this, other) as LongBinding

/** @see IntegerExpression.add */
inline operator fun ObservableIntegerValue.plus(other: Int): IntegerBinding =
    Bindings.add(this, other) as IntegerBinding

/** @see IntegerExpression.add */
inline operator fun Int.plus(other: ObservableIntegerValue): IntegerBinding =
    Bindings.add(this, other) as IntegerBinding

/** @see IntegerExpression.subtract */
inline operator fun ObservableIntegerValue.minus(other: Double): DoubleBinding = Bindings.subtract(this, other)

/** @see IntegerExpression.subtract */
inline operator fun Double.minus(other: ObservableIntegerValue): DoubleBinding = Bindings.subtract(this, other)

/** @see IntegerExpression.subtract */
inline operator fun ObservableIntegerValue.minus(other: Float): FloatBinding =
    Bindings.subtract(this, other) as FloatBinding

/** @see IntegerExpression.subtract */
inline operator fun Float.minus(other: ObservableIntegerValue): FloatBinding =
    Bindings.subtract(this, other) as FloatBinding

/** @see IntegerExpression.subtract */
inline operator fun ObservableIntegerValue.minus(other: Long): LongBinding =
    Bindings.subtract(this, other) as LongBinding

/** @see IntegerExpression.subtract */
inline operator fun Long.minus(other: ObservableIntegerValue): LongBinding =
    Bindings.subtract(this, other) as LongBinding

/** @see IntegerExpression.subtract */
inline operator fun ObservableIntegerValue.minus(other: Int): IntegerBinding =
    Bindings.subtract(this, other) as IntegerBinding

/** @see IntegerExpression.subtract */
inline operator fun Int.minus(other: ObservableIntegerValue): IntegerBinding =
    Bindings.subtract(this, other) as IntegerBinding

/** @see IntegerExpression.multiply */
inline operator fun ObservableIntegerValue.times(other: Double): DoubleBinding = Bindings.multiply(this, other)

/** @see IntegerExpression.multiply */
inline operator fun Double.times(other: ObservableIntegerValue): DoubleBinding = Bindings.multiply(this, other)

/** @see IntegerExpression.multiply */
inline operator fun ObservableIntegerValue.times(other: Float): FloatBinding =
    Bindings.multiply(this, other) as FloatBinding

/** @see IntegerExpression.multiply */
inline operator fun Float.times(other: ObservableIntegerValue): FloatBinding =
    Bindings.multiply(this, other) as FloatBinding

/** @see IntegerExpression.multiply */
inline operator fun ObservableIntegerValue.times(other: Long): LongBinding =
    Bindings.multiply(this, other) as LongBinding

/** @see IntegerExpression.multiply */
inline operator fun Long.times(other: ObservableIntegerValue): LongBinding =
    Bindings.multiply(this, other) as LongBinding

/** @see IntegerExpression.multiply */
inline operator fun ObservableIntegerValue.times(other: Int): IntegerBinding =
    Bindings.multiply(this, other) as IntegerBinding

/** @see IntegerExpression.multiply */
inline operator fun Int.times(other: ObservableIntegerValue): IntegerBinding =
    Bindings.multiply(this, other) as IntegerBinding

/** @see IntegerExpression.divide */
inline operator fun ObservableIntegerValue.div(other: Double): DoubleBinding = Bindings.divide(this, other)

/** @see IntegerExpression.divide */
inline operator fun Double.div(other: ObservableIntegerValue): DoubleBinding = Bindings.divide(this, other)

/** @see IntegerExpression.divide */
inline operator fun ObservableIntegerValue.div(other: Float): FloatBinding =
    Bindings.divide(this, other) as FloatBinding

/** @see IntegerExpression.divide */
inline operator fun Float.div(other: ObservableIntegerValue): FloatBinding =
    Bindings.divide(this, other) as FloatBinding

/** @see IntegerExpression.divide */
inline operator fun ObservableIntegerValue.div(other: Long): LongBinding = Bindings.divide(this, other) as LongBinding

/** @see IntegerExpression.divide */
inline operator fun Long.div(other: ObservableIntegerValue): LongBinding = Bindings.divide(this, other) as LongBinding

/** @see IntegerExpression.divide */
inline operator fun ObservableIntegerValue.div(other: Int): IntegerBinding =
    Bindings.divide(this, other) as IntegerBinding

/** @see IntegerExpression.divide */
inline operator fun Int.div(other: ObservableIntegerValue): IntegerBinding =
    Bindings.divide(this, other) as IntegerBinding


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_TreeView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.TreeView
import kotlin.Int
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see TreeView.setOnEditStart
 */
public inline fun <T> TreeView<T>.onEditStart(noinline action: (TreeView.EditEvent<T>) -> Unit) {
    return setOnEditStart(action)
}

/**
 * @see TreeView.setOnEditCommit
 */
public inline fun <T> TreeView<T>.onEditCommit(noinline action: (TreeView.EditEvent<T>) -> Unit) {
    return setOnEditCommit(action)
}

/**
 * @see TreeView.setOnEditCancel
 */
public inline fun <T> TreeView<T>.onEditCancel(noinline action: (TreeView.EditEvent<T>) -> Unit) {
    return setOnEditCancel(action)
}

/**
 * @see TreeView.setOnScrollTo
 */
public inline fun <T> TreeView<T>.onScrollTo(noinline action: (ScrollToEvent<Int>) -> Unit) {
    return setOnScrollTo(action)
}


<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/text/GlyphTest.kt<|end_filename|>
package ktfx.controlsfx.text

import com.hendraanggrian.ktfx.test.initToolkit
import javafx.scene.paint.Color
import org.controlsfx.glyphfont.Glyph
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class GlyphTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun glyph() {
        val glyph = "System" glyph "A"
        assertEquals("System", glyph.fontFamily)
        assertEquals("A", glyph.icon)
    }

    @Test
    fun family() {
        val glyph = Glyph() family "System"
        assertEquals("System", glyph.fontFamily)
    }

    @Test
    fun color() {
        val glyph = Glyph() color Color.AQUA
        assertEquals(Color.AQUA, glyph.textFill)
    }

    @Test
    fun size() {
        val glyph = Glyph() size 18.0
        assertEquals(18.0, glyph.fontSize)
    }

    @Test
    fun sizeFactor() {
        val glyph = Glyph() sizeFactor 2
        assertEquals(13.0, glyph.fontSize)
    }

    @Test
    fun useHoverEffect() {
        val glyph = Glyph() useHoverEffect true
        assertTrue(Glyph.STYLE_HOVER_EFFECT in glyph.styleClass)
    }

    @Test
    fun useGradientEffect() {
        val glyph = Glyph() useGradientEffect true
        assertTrue(Glyph.STYLE_GRADIENT in glyph.styleClass)
    }
}

<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/controls/Decorator.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.controls

import javafx.collections.ObservableList
import javafx.scene.Node
import org.controlsfx.control.decoration.Decoration
import org.controlsfx.control.decoration.Decorator

/** Adds the given decoration to the given node. */
inline fun Node.addDecoration(decoration: Decoration): Unit = Decorator.addDecoration(this, decoration)

/** Removes the given decoration from the given node. */
inline fun Node.removeDecoration(decoration: Decoration): Unit = Decorator.removeDecoration(this, decoration)

/** Removes all the decorations that have previously been set on the given node. */
inline fun Node.clearDecorations(): Unit = Decorator.removeAllDecorations(this)

/** Returns all the currently set decorations for the given node. */
inline val Node.decorations: ObservableList<Decoration> get() = Decorator.getDecorations(this)


<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/dialogs/ProgressDialogsTest.kt<|end_filename|>
package ktfx.controlsfx.dialogs

import javafx.concurrent.Service
import javafx.stage.Stage
import ktfx.buildService
import com.hendraanggrian.ktfx.test.DialogShowingTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class ProgressDialogsTest : DialogShowingTest() {
    private lateinit var helloWorldService: Service<String>

    override fun start(stage: Stage) {
        super.start(stage)
        helloWorldService = buildService { call { "Hello world" } }
    }

    @Test
    fun exceptionDialog() {
        interact {
            progressDialog("Progress dialog", sampleGraphic, helloWorldService) {
                closeOnShow(this)
                assertEquals("Progress dialog", headerText)
                assertEquals(sampleGraphic, graphic)
            }.get()
            progressDialog(helloWorldService) {
                closeOnShow(this)
                assertEquals("Progress dialog", headerText)
                assertEquals(sampleGraphic, graphic)
            }.get()
        }
    }
}

<|start_filename|>ktfx-layouts/src/javafx/scene/KtfxSubScene.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.Parent
import javafx.scene.SubScene
import javafx.scene.layout.Pane
import kotlin.contracts.ExperimentalContracts

/**
 * [SubScene] with dynamic-layout dsl support.
 * Invoking dsl will only set its root.
 */
open class KtfxSubScene(root: Parent, width: Double, height: Double) : SubScene(root, width, height), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { root = it as? Pane ?: Pane(it) }
}


<|start_filename|>ktfx-commons/src/ktfx/bindings/BindingsDouble.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("BindingsKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.Observable
import javafx.beans.binding.Bindings
import javafx.beans.binding.DoubleBinding
import javafx.beans.value.ObservableBooleanValue
import javafx.beans.value.ObservableDoubleValue
import javafx.beans.value.ObservableFloatValue
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableLongValue
import javafx.beans.value.ObservableObjectValue
import javafx.collections.ObservableList
import javafx.collections.ObservableMap
import javafx.collections.ObservableSet
import ktfx.collections.observableListOf
import ktfx.collections.toObservableList
import java.util.concurrent.Callable

/** Create a [DoubleBinding] with multiple [Observable] dependencies. */
inline fun doubleBindingOf(vararg dependencies: Observable, noinline valueProvider: () -> Double): DoubleBinding =
    Bindings.createDoubleBinding(Callable(valueProvider), *dependencies)

/** Create a [DoubleBinding] with multiple [Observable] dependencies using collection. */
fun doubleBindingOf(dependencies: Collection<Observable>, valueProvider: () -> Double): DoubleBinding =
    doubleBindingOf(*dependencies.toTypedArray(), valueProvider = valueProvider)

/** Create an [DoubleBinding] with single [ObservableList] dependency. */
fun <E> ObservableList<E>.asDouble(valueProvider: (List<E>) -> Double): DoubleBinding =
    object : DoubleBinding() {
        override fun dispose(): Unit = unbind(this@asDouble)
        override fun computeValue(): Double = valueProvider(this@asDouble)
        override fun getDependencies(): ObservableList<*> = this@asDouble

        init {
            bind(this@asDouble)
        }
    }

/** Create an [DoubleBinding] with single [ObservableSet] dependency. */
fun <E> ObservableSet<E>.asDouble(valueProvider: (Set<E>) -> Double): DoubleBinding =
    object : DoubleBinding() {
        override fun dispose(): Unit = unbind(this@asDouble)
        override fun computeValue(): Double = valueProvider(this@asDouble)
        override fun getDependencies(): ObservableList<*> = this@asDouble.toObservableList()

        init {
            bind(this@asDouble)
        }
    }

/** Create an [DoubleBinding] with single [ObservableMap] dependency. */
fun <K, V> ObservableMap<K, V>.asDouble(valueProvider: (Map<K, V>) -> Double): DoubleBinding =
    object : DoubleBinding() {
        override fun dispose(): Unit = unbind(this@asDouble)
        override fun computeValue(): Double = valueProvider(this@asDouble)
        override fun getDependencies(): ObservableList<*> = this@asDouble.keys.toObservableList()

        init {
            bind(this@asDouble)
        }
    }

/** Create a [DoubleBinding] with single [ObservableObjectValue] dependency. */
fun <V> ObservableObjectValue<V>.asDouble(valueProvider: (V?) -> Double): DoubleBinding =
    object : DoubleBinding() {
        override fun dispose(): Unit = unbind(this@asDouble)
        override fun computeValue(): Double = valueProvider(this@asDouble.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asDouble)

        init {
            bind(this@asDouble)
        }
    }

/** Create a [DoubleBinding] with single [ObservableBooleanValue] dependency. */
fun ObservableBooleanValue.asDouble(valueProvider: (Boolean) -> Double): DoubleBinding =
    object : DoubleBinding() {
        override fun dispose(): Unit = unbind(this@asDouble)
        override fun computeValue(): Double = valueProvider(this@asDouble.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asDouble)

        init {
            bind(this@asDouble)
        }
    }

/** Create a [DoubleBinding] with single [ObservableDoubleValue] dependency. */
fun ObservableDoubleValue.asDouble(valueProvider: (Double) -> Double): DoubleBinding =
    object : DoubleBinding() {
        override fun dispose(): Unit = unbind(this@asDouble)
        override fun computeValue(): Double = valueProvider(this@asDouble.value as Double)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asDouble)

        init {
            bind(this@asDouble)
        }
    }

/** Create a [DoubleBinding] with single [ObservableFloatValue] dependency. */
fun ObservableFloatValue.asDouble(valueProvider: (Float) -> Double): DoubleBinding =
    object : DoubleBinding() {
        override fun dispose(): Unit = unbind(this@asDouble)
        override fun computeValue(): Double = valueProvider(this@asDouble.value as Float)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asDouble)

        init {
            bind(this@asDouble)
        }
    }

/** Create a [DoubleBinding] with single [ObservableIntegerValue] dependency. */
fun ObservableIntegerValue.asDouble(valueProvider: (Int) -> Double): DoubleBinding =
    object : DoubleBinding() {
        override fun dispose(): Unit = unbind(this@asDouble)
        override fun computeValue(): Double = valueProvider(this@asDouble.value as Int)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asDouble)

        init {
            bind(this@asDouble)
        }
    }

/** Create a [DoubleBinding] with single [ObservableLongValue] dependency. */
fun ObservableLongValue.asDouble(valueProvider: (Long) -> Double): DoubleBinding =
    object : DoubleBinding() {
        override fun dispose(): Unit = unbind(this@asDouble)
        override fun computeValue(): Double = valueProvider(this@asDouble.value as Long)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asDouble)

        init {
            bind(this@asDouble)
        }
    }


<|start_filename|>ktfx-listeners/src/javafx/collections/ObservableArray.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.collections.ArrayChangeListener
import javafx.collections.ObservableArray

/** Add a listener to this observable array. */
inline fun <T : ObservableArray<T>> ObservableArray<T>.listener(
    noinline listener: (array: T, changed: Boolean, from: Int, to: Int) -> Unit
): ArrayChangeListener<T> = ArrayChangeListener<T>(listener).also { addListener(it) }


<|start_filename|>thirdparty/jfoenix-listeners/tests/src/com/jfoenix/controls/JFXDialogTest.kt<|end_filename|>
package ktfx.jfoenix.listeners

import com.jfoenix.controls.JFXDialog
import com.jfoenix.controls.events.JFXDialogEvent
import ktfx.jfoenix.test.BaseJFXDialogTest

class JFXDialogTest : BaseJFXDialogTest() {

    override fun JFXDialog.callOnDialogClosed(action: (JFXDialogEvent) -> Unit) = onDialogClosed(action)
    override fun JFXDialog.callOnDialogOpened(action: (JFXDialogEvent) -> Unit) = onDialogOpened(action)
}

<|start_filename|>ktfx-layouts/src/javafx/scene/control/KtfxMenuBar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.Menu
import javafx.scene.control.MenuBar
import kotlin.contracts.ExperimentalContracts

/**
 * [MenuBar] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxMenuBar : MenuBar(), MenuManager {

    final override fun <C : Menu> addChild(child: C): C = child.also { menus += it }

    /** Call [MenuManager.menu] by string invocation. */
    inline operator fun String.invoke(
        graphic: Node? = null,
        configuration: (@KtfxLayoutDslMarker KtfxMenu).() -> Unit
    ): Menu = menu(this, graphic, configuration)
}


<|start_filename|>thirdparty/jfoenix-coroutines/tests/src/com/jfoenix/controls/JFXAutoCompletePopupTest.kt<|end_filename|>
package ktfx.jfoenix.coroutines

import com.jfoenix.controls.JFXAutoCompletePopup
import com.jfoenix.controls.events.JFXAutoCompleteEvent
import kotlinx.coroutines.Dispatchers
import ktfx.jfoenix.test.BaseJFXAutoCompletePopupTest

class JFXAutoCompletePopupTest : BaseJFXAutoCompletePopupTest() {

    override fun <E> JFXAutoCompletePopup<E>.callSelectionHandler(action: (JFXAutoCompleteEvent<E>) -> Unit) =
        selectionHandler(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/ListViewTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.control.ListView
import javafx.scene.control.ScrollToEvent
import com.hendraanggrian.ktfx.test.BaseListViewTest

class ListViewTest : BaseListViewTest() {

    override fun <E> ListView<E>.callOnEditStart(action: (ListView.EditEvent<E>) -> Unit) = onEditStart(action)
    override fun <E> ListView<E>.callOnEditCommit(action: (ListView.EditEvent<E>) -> Unit) = onEditCommit(action)
    override fun <E> ListView<E>.callOnEditCancel(action: (ListView.EditEvent<E>) -> Unit) = onEditCancel(action)
    override fun <E> ListView<E>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit) = onScrollTo(action)
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/ButtonBaseTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.event.ActionEvent
import javafx.scene.control.ButtonBase
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseButtonBaseTest

class ButtonBaseTest : BaseButtonBaseTest() {

    override fun ButtonBase.callOnAction(action: (ActionEvent) -> Unit) =
        onAction(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-layouts/src/javafx/scene/control/KtfxTab.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.Tab
import kotlin.contracts.ExperimentalContracts

/**
 * [Tab] with dynamic-layout dsl support.
 * Invoking dsl will only set its content.
 */
open class KtfxTab(title: String?, content: Node?) : Tab(title, content), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { content = it }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/CubicCurveToTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.CubicCurveTo
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class CubicCurveToTest : LayoutsTest<KtfxPath, CubicCurveTo>() {

    override fun manager() = KtfxPath()
    override fun KtfxPath.childCount() = elements.size
    override fun child1() = cubicCurveTo { }
    override fun KtfxPath.child2() = cubicCurveTo()
    override fun KtfxPath.child3() = cubicCurveTo { }

    override fun CubicCurveTo.testDefaultValues() {
        assertEquals(0.0, controlX1)
        assertEquals(0.0, controlX2)
        assertEquals(0.0, controlY1)
        assertEquals(0.0, controlY2)
        assertEquals(0.0, x)
        assertEquals(0.0, y)
    }
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_ChoiceBox.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.ChoiceBox
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see ChoiceBox.setOnAction
 */
public inline fun ChoiceBox<*>.onAction(noinline action: (ActionEvent) -> Unit) {
    return setOnAction(action)
}

/**
 * @see ChoiceBox.setOnShowing
 */
public inline fun ChoiceBox<*>.onShowing(noinline action: (Event) -> Unit) {
    return setOnShowing(action)
}

/**
 * @see ChoiceBox.setOnShown
 */
public inline fun ChoiceBox<*>.onShown(noinline action: (Event) -> Unit) {
    return setOnShown(action)
}

/**
 * @see ChoiceBox.setOnHiding
 */
public inline fun ChoiceBox<*>.onHiding(noinline action: (Event) -> Unit) {
    return setOnHiding(action)
}

/**
 * @see ChoiceBox.setOnHidden
 */
public inline fun ChoiceBox<*>.onHidden(noinline action: (Event) -> Unit) {
    return setOnHidden(action)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/controls/BordersTest.kt<|end_filename|>
package ktfx.controls

import javafx.geometry.Insets
import javafx.scene.layout.BorderRepeat
import javafx.scene.layout.BorderStrokeStyle
import javafx.scene.layout.BorderWidths
import javafx.scene.layout.CornerRadii
import javafx.scene.layout.Region
import javafx.scene.paint.Color
import com.hendraanggrian.ktfx.test.SampleImage
import com.hendraanggrian.ktfx.test.initToolkit
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class BordersTest {
    private lateinit var region: Region

    @BeforeTest fun start() {
        initToolkit()
        region = Region()
    }

    @Test
    fun multiple() {
        region.border {
            stroke { }
            image(SampleImage()) { }
        }
        assertEquals(1, region.border.strokes.size)
        assertEquals(1, region.border.images.size)
    }

    @Test
    fun singleStroke() {
        region.borderStroke {
            stroke = Color.RED
            style = BorderStrokeStyle.DOTTED
            radii = CornerRadii(5.0)
            widths = BorderWidths.FULL
            insets = Insets(10.0)
        }
        region.border.strokes.first().let {
            assertEquals(Color.RED, it.topStroke)
            assertEquals(Color.RED, it.leftStroke)
            assertEquals(Color.RED, it.rightStroke)
            assertEquals(Color.RED, it.bottomStroke)
            assertEquals(BorderStrokeStyle.DOTTED, it.topStyle)
            assertEquals(BorderStrokeStyle.DOTTED, it.leftStyle)
            assertEquals(BorderStrokeStyle.DOTTED, it.rightStyle)
            assertEquals(BorderStrokeStyle.DOTTED, it.bottomStyle)
            assertEquals(CornerRadii(5.0), it.radii)
            assertEquals(BorderWidths.FULL, it.widths)
            assertEquals(Insets(10.0), it.insets)
        }
    }

    @Test
    fun singleImage() {
        val sample = SampleImage()
        region.borderImage(sample) {
            widths = BorderWidths.FULL
            insets = Insets(10.0)
            slices = BorderWidths.FULL
            isFilled = true
            repeat = BorderRepeat.ROUND
        }
        region.border.images.first().let {
            assertEquals(sample, it.image)
            assertEquals(BorderWidths.FULL, it.widths)
            assertEquals(Insets(10.0), it.insets)
            assertEquals(BorderWidths.FULL, it.slices)
            assertTrue(it.isFilled)
            assertEquals(BorderRepeat.ROUND, it.repeatX)
            assertEquals(BorderRepeat.ROUND, it.repeatY)
        }
    }
}


<|start_filename|>ktfx-commons/src/ktfx/bindings/ConditionalBinding.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.DoubleBinding
import javafx.beans.binding.NumberBinding
import javafx.beans.binding.ObjectBinding
import javafx.beans.binding.StringBinding
import javafx.beans.binding.When
import javafx.beans.value.ObservableBooleanValue
import javafx.beans.value.ObservableNumberValue
import javafx.beans.value.ObservableObjectValue
import javafx.beans.value.ObservableStringValue

/** Creates a binding that calculates the result of a ternary expression. */
inline fun given(condition: ObservableBooleanValue): When = Bindings.`when`(condition)

/** @see When.then */
inline infix fun When.then(value: ObservableNumberValue): When.NumberConditionBuilder = then(value)

/** @see When.then */
inline infix fun When.then(value: Double): When.NumberConditionBuilder = then(value)

/** @see When.then */
inline infix fun When.then(value: Float): When.NumberConditionBuilder = then(value)

/** @see When.then */
inline infix fun When.then(value: Long): When.NumberConditionBuilder = then(value)

/** @see When.then */
inline infix fun When.then(value: Int): When.NumberConditionBuilder = then(value)

/** @see When.NumberConditionBuilder.otherwise */
inline infix fun When.NumberConditionBuilder.otherwise(value: ObservableNumberValue): NumberBinding = otherwise(value)

/** @see When.NumberConditionBuilder.otherwise */
inline infix fun When.NumberConditionBuilder.otherwise(value: Double): DoubleBinding = otherwise(value)

/** @see When.NumberConditionBuilder.otherwise */
inline infix fun When.NumberConditionBuilder.otherwise(value: Float): NumberBinding = otherwise(value)

/** @see When.NumberConditionBuilder.otherwise */
inline infix fun When.NumberConditionBuilder.otherwise(value: Long): NumberBinding = otherwise(value)

/** @see When.NumberConditionBuilder.otherwise */
inline infix fun When.NumberConditionBuilder.otherwise(value: Int): NumberBinding = otherwise(value)

/** @see When.then */
inline infix fun When.then(value: ObservableBooleanValue): When.BooleanConditionBuilder = then(value)

/** @see When.then */
inline infix fun When.then(value: Boolean): When.BooleanConditionBuilder = then(value)

/** @see When.BooleanConditionBuilder.otherwise */
inline infix fun When.BooleanConditionBuilder.otherwise(value: ObservableBooleanValue): BooleanBinding =
    otherwise(value)

/** @see When.BooleanConditionBuilder.otherwise */
inline infix fun When.BooleanConditionBuilder.otherwise(value: Boolean): BooleanBinding = otherwise(value)

/** @see When.then */
inline infix fun When.then(value: ObservableStringValue): When.StringConditionBuilder = then(value)

/** @see When.then */
inline infix fun When.then(value: String): When.StringConditionBuilder = then(value)

/** @see When.StringConditionBuilder.otherwise */
inline infix fun When.StringConditionBuilder.otherwise(value: ObservableStringValue): StringBinding = otherwise(value)

/** @see [When.StringConditionBuilder.otherwise */
inline infix fun When.StringConditionBuilder.otherwise(value: String): StringBinding = otherwise(value)

/** @see When.then */
inline infix fun <T> When.then(value: ObservableObjectValue<T>): When.ObjectConditionBuilder<T> = then(value)

/** @see When.then */
inline infix fun <T> When.then(value: T?): When.ObjectConditionBuilder<T> = then(value)

/** @see When.ObjectConditionBuilder.otherwise */
inline infix fun <T> When.ObjectConditionBuilder<T>.otherwise(value: ObservableObjectValue<T>): ObjectBinding<T> =
    otherwise(value)

/** @see When.ObjectConditionBuilder.otherwise */
inline infix fun <T> When.ObjectConditionBuilder<T>.otherwise(value: T?): ObjectBinding<T> = otherwise(value)


<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXTogglePane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTogglePane
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXTogglePane] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.jfxTogglePane(): JFXTogglePane = jfxTogglePane() { }

/**
 * Create a [JFXTogglePane] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun jfxTogglePane(configuration: (@KtfxLayoutDslMarker KtfxJFXTogglePane).() -> Unit):
    JFXTogglePane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXTogglePane()
    child.configuration()
    return child
}

/**
 * Add a [JFXTogglePane] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.jfxTogglePane(
    configuration: (
        @KtfxLayoutDslMarker
        KtfxJFXTogglePane
    ).() -> Unit
): JFXTogglePane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXTogglePane()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXTogglePane].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledJFXTogglePane(vararg styleClass: String, id: String? = null): JFXTogglePane =
    styledJFXTogglePane(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXTogglePane] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledJFXTogglePane(vararg styleClass: String, id: String? = null):
    JFXTogglePane = styledJFXTogglePane(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [JFXTogglePane] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledJFXTogglePane(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxJFXTogglePane).() -> Unit
): JFXTogglePane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXTogglePane()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXTogglePane] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledJFXTogglePane(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxJFXTogglePane).() -> Unit
): JFXTogglePane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXTogglePane()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_TreeTableView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.TreeItem
import javafx.scene.control.TreeTableView
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [TreeTableView] to this manager.
 *
 * @return the control added.
 */
public fun <S> NodeManager.treeTableView(root: TreeItem<S>? = null): TreeTableView<S> =
    treeTableView(root = root) { }

/**
 * Create a [TreeTableView] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun <S> treeTableView(
    root: TreeItem<S>? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        TreeTableView<S>
    ).() -> Unit
): TreeTableView<S> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TreeTableView<S>(root)
    child.configuration()
    return child
}

/**
 * Add a [TreeTableView] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun <S> NodeManager.treeTableView(
    root: TreeItem<S>? = null,
    configuration: (@KtfxLayoutDslMarker TreeTableView<S>).() -> Unit
): TreeTableView<S> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TreeTableView<S>(root)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [TreeTableView].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun <S> styledTreeTableView(
    root: TreeItem<S>? = null,
    vararg styleClass: String,
    id: String? = null
): TreeTableView<S> = styledTreeTableView(root = root, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [TreeTableView] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun <S> NodeManager.styledTreeTableView(
    root: TreeItem<S>? = null,
    vararg styleClass: String,
    id: String? = null
): TreeTableView<S> = styledTreeTableView(root = root, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [TreeTableView] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun <S> styledTreeTableView(
    root: TreeItem<S>? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker TreeTableView<S>).() -> Unit
): TreeTableView<S> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TreeTableView<S>(root)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [TreeTableView] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun <S> NodeManager.styledTreeTableView(
    root: TreeItem<S>? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker TreeTableView<S>).() -> Unit
): TreeTableView<S> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TreeTableView<S>(root)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-listeners/src/ktfx/jfoenix/listeners/_JFXDrawer.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.jfoenix.listeners

import com.jfoenix.controls.JFXDrawer
import com.jfoenix.controls.events.JFXDrawerEvent
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see JFXDrawer.setOnDrawerClosed
 */
public inline fun JFXDrawer.onDrawerClosed(noinline action: (JFXDrawerEvent) -> Unit) {
    return setOnDrawerClosed(action)
}

/**
 * @see JFXDrawer.setOnDrawerClosing
 */
public inline fun JFXDrawer.onDrawerClosing(noinline action: (JFXDrawerEvent) -> Unit) {
    return setOnDrawerClosing(action)
}

/**
 * @see JFXDrawer.setOnDrawerOpened
 */
public inline fun JFXDrawer.onDrawerOpened(noinline action: (JFXDrawerEvent) -> Unit) {
    return setOnDrawerOpened(action)
}

/**
 * @see JFXDrawer.setOnDrawerOpening
 */
public inline fun JFXDrawer.onDrawerOpening(noinline action: (JFXDrawerEvent) -> Unit) {
    return setOnDrawerOpening(action)
}


<|start_filename|>ktfx-listeners/tests/src/javafx/collections/ObservableArrayTest.kt<|end_filename|>
package ktfx.listeners

import javafx.beans.Observable
import javafx.collections.ObservableArray
import com.hendraanggrian.ktfx.test.BaseObservableArrayTest

class ObservableArrayTest : BaseObservableArrayTest() {

    override fun <T : ObservableArray<T>> ObservableArray<T>.callListener(action: (Observable, Boolean, Int, Int) -> Unit) {
        listener(action)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/controls/Transforms.kt<|end_filename|>
package ktfx.controls

import javafx.scene.Node
import javafx.scene.transform.Affine
import javafx.scene.transform.Rotate
import javafx.scene.transform.Scale
import javafx.scene.transform.Shear
import javafx.scene.transform.Translate

/**
 * Adds [Affine] transformation.
 * @param configuration the configuration block that customizes transformation.
 * @return the transformation added.
 */
fun Node.affineTransformation(configuration: Affine.() -> Unit): Affine = Affine().also {
    it.configuration()
    transforms += it
}

/**
 * Adds [Rotate] transformation.
 * @param configuration the configuration block that customizes transformation.
 * @return the transformation added.
 */
fun Node.rotateTransformation(configuration: Rotate.() -> Unit): Rotate = Rotate().also {
    it.configuration()
    transforms += it
}

/**
 * Adds [Scale] transformation.
 * @param configuration the configuration block that customizes transformation.
 * @return the transformation added.
 */
fun Node.scaleTransformation(configuration: Scale.() -> Unit): Scale = Scale().also {
    it.configuration()
    transforms += it
}

/**
 * Adds [Shear] transformation.
 * @param configuration the configuration block that customizes transformation.
 * @return the transformation added.
 */
fun Node.shearTransformation(configuration: Shear.() -> Unit): Shear = Shear().also {
    it.configuration()
    transforms += it
}

/**
 * Adds [Translate] transformation.
 * @param configuration the configuration block that customizes transformation.
 * @return the transformation added.
 */
fun Node.translateTransformation(configuration: Translate.() -> Unit): Translate = Translate().also {
    it.configuration()
    transforms += it
}


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/Names.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen

import com.hendraanggrian.kotlinpoet.VARARG
import com.hendraanggrian.kotlinpoet.classOf
import com.hendraanggrian.kotlinpoet.memberOf
import com.hendraanggrian.kotlinpoet.typeVarOf
import com.squareup.kotlinpoet.ParameterSpec

const val KTFX_LAYOUTS = "ktfx.layouts"
const val KOTLIN_CONTRACTS = "kotlin.contracts"

val OPT_IN = "".classOf("OptIn")
val EXPERIMENTAL_CONTRACTS = KOTLIN_CONTRACTS.classOf("ExperimentalContracts")
val CONTRACT = KOTLIN_CONTRACTS.memberOf("contract")
val EXACTLY_ONCE = "$KOTLIN_CONTRACTS.InvocationKind".memberOf("EXACTLY_ONCE")

val DSL_MARKER = KTFX_LAYOUTS.classOf("KtfxLayoutDslMarker")

val T = "T".typeVarOf()
val S = "S".typeVarOf()
val X = "X".typeVarOf()
val Y = "Y".typeVarOf()

fun List<ParameterSpec>.toString(namedArgument: Boolean, commaSuffix: Boolean): String =
    buildString {
        append(joinToString {
            var s = buildString {
                append(it.name)
                if (namedArgument) append(" = ${it.name}")
            }
            if (VARARG in it.modifiers) {
                val index = s.lastIndexOf(it.name)
                s = s.substring(0, index) + '*' + s.substring(index)
            }
            s
        })
        if (commaSuffix && isNotEmpty()) append(", ")
    }

<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/StringValueBindingTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.stringPropertyOf
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class StringValueBindingTest {

    @Test
    fun eq() {
        assertFalse((stringPropertyOf("Hello") eq stringPropertyOf("World")).value)
        assertFalse((stringPropertyOf("Hello") eq "World").value)
        assertFalse(("Hello" eq stringPropertyOf("World")).value)
    }

    @Test
    fun neq() {
        assertTrue((stringPropertyOf("Hello") neq stringPropertyOf("World")).value)
        assertTrue((stringPropertyOf("Hello") neq "World").value)
        assertTrue(("Hello" neq stringPropertyOf("World")).value)
    }

    @Test
    fun eqIg() {
        assertTrue((stringPropertyOf("Hello") eqIg stringPropertyOf("hello")).value)
        assertTrue((stringPropertyOf("Hello") eqIg "hello").value)
        assertTrue(("Hello" eqIg stringPropertyOf("hello")).value)
    }

    @Test
    fun neqIg() {
        assertFalse((stringPropertyOf("Hello") neqIg stringPropertyOf("hello")).value)
        assertFalse((stringPropertyOf("Hello") neqIg "hello").value)
        assertFalse(("Hello" neqIg stringPropertyOf("hello")).value)
    }

    @Test
    fun greater() {
        assertFalse((stringPropertyOf("Hello") greater stringPropertyOf("World")).value)
        assertFalse((stringPropertyOf("Hello") greater "World").value)
        assertFalse(("Hello" greater stringPropertyOf("World")).value)
    }

    @Test
    fun less() {
        assertTrue((stringPropertyOf("Hello") less stringPropertyOf("World")).value)
        assertTrue((stringPropertyOf("Hello") less "World").value)
        assertTrue(("Hello" less stringPropertyOf("World")).value)
    }

    @Test
    fun greaterEq() {
        assertTrue((stringPropertyOf("Hello") greaterEq stringPropertyOf("Hello")).value)
        assertTrue((stringPropertyOf("Hello") greaterEq "Hello").value)
        assertTrue(("Hello" greaterEq stringPropertyOf("Hello")).value)
    }

    @Test
    fun lessEq() {
        assertTrue((stringPropertyOf("Hello") lessEq stringPropertyOf("Hello")).value)
        assertTrue((stringPropertyOf("Hello") lessEq "Hello").value)
        assertTrue(("Hello" lessEq stringPropertyOf("Hello")).value)
    }

    @Test
    fun length() = assertEquals(5, (stringPropertyOf("Hello").length().value))
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/textfield/CustomPasswordFieldTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.textfield.CustomPasswordField

class CustomPasswordFieldTest : LayoutsTest<KtfxPane, CustomPasswordField>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = customPasswordField { }
    override fun KtfxPane.child2() = customPasswordField()
    override fun KtfxPane.child3() = customPasswordField { }
}

<|start_filename|>buildSrc/src/releases.kt<|end_filename|>
const val RELEASE_GROUP = "com.hendraanggrian.ktfx"
const val RELEASE_ARTIFACT = "ktfx"
const val RELEASE_VERSION = "0.1-SNAPSHOT"
const val RELEASE_DESCRIPTION = "Kotlin extensions for JavaFX app development"
const val RELEASE_GITHUB = "https://github.com/hendraanggrian/$RELEASE_ARTIFACT"

fun getGithubRemoteUrl(artifact: String = RELEASE_ARTIFACT) =
    `java.net`.URL("$RELEASE_GITHUB/tree/main/$artifact/src")

<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/HiddenSidesPaneTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.HiddenSidesPane

class HiddenSidesPaneTest : LayoutsTest<KtfxPane, HiddenSidesPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = hiddenSidesPane { }
    override fun KtfxPane.child2() = hiddenSidesPane()
    override fun KtfxPane.child3() = hiddenSidesPane { }
}

<|start_filename|>ktfx-commons/src/ktfx/Properties.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("PropertiesKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx

import javafx.beans.property.BooleanProperty
import javafx.beans.property.DoubleProperty
import javafx.beans.property.FloatProperty
import javafx.beans.property.IntegerProperty
import javafx.beans.property.LongProperty
import javafx.beans.property.Property
import javafx.beans.property.ReadOnlyBooleanProperty
import javafx.beans.property.ReadOnlyDoubleProperty
import javafx.beans.property.ReadOnlyFloatProperty
import javafx.beans.property.ReadOnlyIntegerProperty
import javafx.beans.property.ReadOnlyLongProperty
import javafx.beans.property.ReadOnlyProperty

/** Revert the effect of [BooleanProperty.asObject]. */
inline fun Property<Boolean>.asPrimitive(): BooleanProperty =
    BooleanProperty.booleanProperty(this)

/** Revert the effect of [ReadOnlyBooleanProperty.asObject]. */
inline fun ReadOnlyProperty<Boolean>.asPrimitive(): ReadOnlyBooleanProperty =
    ReadOnlyBooleanProperty.readOnlyBooleanProperty(this)

/** Revert the effect of [DoubleProperty.asObject]. */
inline fun Property<Double>.asPrimitive(): DoubleProperty =
    DoubleProperty.doubleProperty(this)

/** Revert the effect of [ReadOnlyDoubleProperty.asObject]. */
inline fun ReadOnlyProperty<Double>.asPrimitive(): ReadOnlyDoubleProperty =
    ReadOnlyDoubleProperty.readOnlyDoubleProperty(this)

/** Revert the effect of [FloatProperty.asObject]. */
inline fun Property<Float>.asPrimitive(): FloatProperty =
    FloatProperty.floatProperty(this)

/** Revert the effect of [ReadOnlyFloatProperty.asObject]. */
inline fun ReadOnlyProperty<Float>.asPrimitive(): ReadOnlyFloatProperty =
    ReadOnlyFloatProperty.readOnlyFloatProperty(this)

/** Revert the effect of [IntegerProperty.asObject]. */
inline fun Property<Int>.asPrimitive(): IntegerProperty =
    IntegerProperty.integerProperty(this)

/** Revert the effect of [ReadOnlyIntegerProperty.asObject]. */
inline fun ReadOnlyProperty<Int>.asPrimitive(): ReadOnlyIntegerProperty =
    ReadOnlyIntegerProperty.readOnlyIntegerProperty(this)

/** Revert the effect of [LongProperty.asObject]. */
inline fun Property<Long>.asPrimitive(): LongProperty =
    LongProperty.longProperty(this)

/** Revert the effect of [ReadOnlyLongProperty.asObject]. */
inline fun ReadOnlyProperty<Long>.asPrimitive(): ReadOnlyLongProperty =
    ReadOnlyLongProperty.readOnlyLongProperty(this)


<|start_filename|>ktfx-listeners/tests/src/javafx/collections/ObservableListTest.kt<|end_filename|>
package ktfx.listeners

import javafx.collections.ListChangeListener
import javafx.collections.ObservableList
import com.hendraanggrian.ktfx.test.BaseObservableListTest

class ObservableListTest : BaseObservableListTest() {

    override fun <E> ObservableList<E>.callListener(action: (ListChangeListener.Change<out E>) -> Unit) {
        listener(action)
    }
}

<|start_filename|>ktfx-commons/tests/src/com/hendraanggrian/ktfx/test/BaseInputTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.EventType
import javafx.scene.Scene
import javafx.scene.input.KeyCode
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseButton
import javafx.scene.input.MouseEvent
import javafx.scene.input.ScrollEvent
import javafx.stage.Stage
import org.testfx.framework.junit.ApplicationTest

/**
 * Application test which can create fake key, mouse and scroll events.
 * @see org.testfx.service.adapter.impl.JavafxRobotAdapter
 */
open class BaseInputTest : ApplicationTest() {
    lateinit var scene: Scene

    var isShiftDown = false
    var isControlDown = false
    var isAltDown = false
    var isMetaDown = false

    var lastButtonPressed: MouseButton? = null
    var isButton1Pressed = false
    var isButton2Pressed = false
    var isButton3Pressed = false
    var sceneMouseX = 0.0
    var sceneMouseY = 0.0
    var screenMouseX = 0.0
    var screenMouseY = 0.0

    override fun start(stage: Stage) {
        scene = stage.testScene("Inputs")
    }

    fun keyEventOf(eventType: EventType<KeyEvent>, code: KeyCode, character: String = ""): KeyEvent {
        val pressed = eventType == KeyEvent.KEY_PRESSED
        if (code == KeyCode.SHIFT) {
            isShiftDown = pressed
        }
        if (code == KeyCode.CONTROL) {
            isControlDown = pressed
        }
        if (code == KeyCode.ALT) {
            isAltDown = pressed
        }
        if (code == KeyCode.META) {
            isMetaDown = pressed
        }
        val typed = eventType == KeyEvent.KEY_TYPED
        val keyChar = if (typed) character else KeyEvent.CHAR_UNDEFINED
        val keyText = if (typed) "" else code.getName()
        return KeyEvent(
            eventType,
            keyChar,
            keyText,
            code,
            isShiftDown,
            isControlDown,
            isAltDown,
            isMetaDown
        )
    }

    @Suppress("NON_EXHAUSTIVE_WHEN")
    fun mouseEventOf(
        eventType: EventType<MouseEvent?>,
        x: Double,
        y: Double,
        mouseButton: MouseButton,
        clickCount: Int
    ): MouseEvent {
        screenMouseX = scene.window.x + scene.x + x
        screenMouseY = scene.window.y + scene.y + y
        sceneMouseX = x
        sceneMouseY = y
        var button = mouseButton
        var type = eventType
        if (type == MouseEvent.MOUSE_PRESSED || type == MouseEvent.MOUSE_RELEASED) {
            val pressed = type == MouseEvent.MOUSE_PRESSED
            when (button) {
                MouseButton.PRIMARY -> isButton1Pressed = pressed
                MouseButton.MIDDLE -> isButton2Pressed = pressed
                MouseButton.SECONDARY -> isButton3Pressed = pressed
            }
            if (pressed) {
                lastButtonPressed = button
            } else {
                if (!(isButton1Pressed || isButton2Pressed || isButton3Pressed)) {
                    lastButtonPressed = MouseButton.NONE
                }
            }
        } else if (type == MouseEvent.MOUSE_MOVED) {
            val someButtonPressed = isButton1Pressed || isButton2Pressed || isButton3Pressed
            if (someButtonPressed) {
                type = MouseEvent.MOUSE_DRAGGED
                button = MouseButton.NONE
            }
        }
        return MouseEvent(
            type, sceneMouseX, sceneMouseY, screenMouseX, screenMouseY,
            button, clickCount, isShiftDown, isControlDown, isAltDown, isMetaDown,
            isButton1Pressed, isButton2Pressed, isButton3Pressed, false, button == MouseButton.SECONDARY, false, null
        )
    }

    fun scrollEventOf(wheelAmount: Int): ScrollEvent {
        screenMouseX = scene.window.x + scene.x + sceneMouseX
        screenMouseY = scene.window.y + scene.y + sceneMouseY
        return ScrollEvent(
            ScrollEvent.SCROLL, sceneMouseX, sceneMouseY, screenMouseX, screenMouseY,
            isShiftDown, isControlDown, isAltDown, isMetaDown, false, false, 0.0,
            wheelAmount * 40.0, 0.0, 0.0, ScrollEvent.HorizontalTextScrollUnits.NONE, 0.0,
            ScrollEvent.VerticalTextScrollUnits.NONE, 0.0, 0, null
        )
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/text/TextTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.text.Text
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class TextTest : LayoutsTest<KtfxTextFlow, Text>() {

    override fun manager() = KtfxTextFlow()
    override fun KtfxTextFlow.childCount() = children.size
    override fun child1() = text { }
    override fun KtfxTextFlow.child2() = text()
    override fun KtfxTextFlow.child3() = text { }

    override fun Text.testDefaultValues() {
        assertEquals("", text)
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_MasterDetailPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import javafx.geometry.Side
import javafx.geometry.Side.RIGHT
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.MasterDetailPane
import kotlin.Boolean
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [MasterDetailPane] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.masterDetailPane(detailSide: Side = RIGHT, showDetailNode: Boolean = true):
    MasterDetailPane = masterDetailPane(
    detailSide = detailSide,
    showDetailNode =
    showDetailNode
) { }

/**
 * Create a [MasterDetailPane] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun masterDetailPane(
    detailSide: Side = RIGHT,
    showDetailNode: Boolean = true,
    configuration: (@KtfxLayoutDslMarker KtfxMasterDetailPane).() -> Unit
): MasterDetailPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxMasterDetailPane(detailSide, showDetailNode)
    child.configuration()
    return child
}

/**
 * Add a [MasterDetailPane] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.masterDetailPane(
    detailSide: Side = RIGHT,
    showDetailNode: Boolean = true,
    configuration: (@KtfxLayoutDslMarker KtfxMasterDetailPane).() -> Unit
): MasterDetailPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxMasterDetailPane(detailSide, showDetailNode)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [MasterDetailPane].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledMasterDetailPane(
    detailSide: Side = RIGHT,
    showDetailNode: Boolean = true,
    vararg styleClass: String,
    id: String? = null
): MasterDetailPane = styledMasterDetailPane(
    detailSide = detailSide,
    showDetailNode =
    showDetailNode,
    styleClass = *styleClass, id = id
) { }

/**
 * Add a styled [MasterDetailPane] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledMasterDetailPane(
    detailSide: Side = RIGHT,
    showDetailNode: Boolean = true,
    vararg styleClass: String,
    id: String? = null
): MasterDetailPane = styledMasterDetailPane(
    detailSide = detailSide,
    showDetailNode =
    showDetailNode,
    styleClass = *styleClass, id = id
) { }

/**
 * Create a styled [MasterDetailPane] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledMasterDetailPane(
    detailSide: Side = RIGHT,
    showDetailNode: Boolean = true,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxMasterDetailPane).() -> Unit
): MasterDetailPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxMasterDetailPane(detailSide, showDetailNode)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [MasterDetailPane] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledMasterDetailPane(
    detailSide: Side = RIGHT,
    showDetailNode: Boolean = true,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxMasterDetailPane).() -> Unit
): MasterDetailPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxMasterDetailPane(detailSide, showDetailNode)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/MenuItemTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.MenuItem
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseMenuItemTest

class MenuItemTest : BaseMenuItemTest() {

    override fun MenuItem.callOnAction(action: (ActionEvent) -> Unit) =
        onAction(Dispatchers.Unconfined) { action(it) }

    override fun MenuItem.callOnMenuValidation(action: (Event) -> Unit) =
        onMenuValidation(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Accordion.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.Accordion
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add an [Accordion] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.accordion(): Accordion = accordion() { }

/**
 * Create an [Accordion] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun accordion(configuration: (@KtfxLayoutDslMarker KtfxAccordion).() -> Unit):
    Accordion {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxAccordion()
    child.configuration()
    return child
}

/**
 * Add an [Accordion] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.accordion(
    configuration: (@KtfxLayoutDslMarker KtfxAccordion).() ->
    Unit
): Accordion {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxAccordion()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Accordion].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledAccordion(vararg styleClass: String, id: String? = null): Accordion =
    styledAccordion(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [Accordion] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledAccordion(vararg styleClass: String, id: String? = null): Accordion =
    styledAccordion(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [Accordion] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledAccordion(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxAccordion).() -> Unit
): Accordion {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxAccordion()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Accordion] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledAccordion(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxAccordion).() -> Unit
): Accordion {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxAccordion()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-coroutines/src/javafx/beans/value/ObservableValue.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxCoroutinesKt")

package ktfx.coroutines

import javafx.beans.Observable
import javafx.beans.value.ChangeListener
import javafx.beans.value.ObservableValue
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

/** Adds a [ChangeListener] which will be notified whenever the value of the [ObservableValue] changes. */
fun <T> ObservableValue<T>.listener(
    context: CoroutineContext = Dispatchers.JavaFx,
    listener: suspend CoroutineScope.(Observable, oldValue: T, value: T) -> Unit
): ChangeListener<T> = ChangeListener<T> { observable, oldValue, newValue ->
    GlobalScope.launch(context) { listener(observable, oldValue, newValue) }
}.also { addListener(it) }


<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/TreeViewTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.TreeView
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseTreeViewTest

class TreeViewTest : BaseTreeViewTest() {

    override fun <E> TreeView<E>.callOnEditStart(action: (TreeView.EditEvent<E>) -> Unit) =
        onEditStart(Dispatchers.Unconfined) { action(it) }

    override fun <E> TreeView<E>.callOnEditCommit(action: (TreeView.EditEvent<E>) -> Unit) =
        onEditCommit(Dispatchers.Unconfined) { action(it) }

    override fun <E> TreeView<E>.callOnEditCancel(action: (TreeView.EditEvent<E>) -> Unit) =
        onEditCancel(Dispatchers.Unconfined) { action(it) }

    override fun <E> TreeView<E>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit) =
        onScrollTo(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>testing/commons/src/com/hendraanggrian/ktfx/test/DialogShowingTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.control.Dialog
import javafx.scene.image.ImageView
import javafx.scene.input.KeyCode
import javafx.stage.Stage
import org.testfx.framework.junit.ApplicationTest

/**
 * Showing dialogs with [Dialog.showAndWait] forces the test to wait for user input.
 * Instead, quickly hit enter whenever dialogs are showing.
 */
open class DialogShowingTest : ApplicationTest() {

    lateinit var stage: Stage
    lateinit var sampleGraphic: ImageView

    override fun start(stage: Stage) {
        this.stage = stage
        stage.testScene<Dialog<*>>()
        sampleGraphic = SampleImageView()
    }

    fun closeOnShow(dialog: Dialog<*>) = dialog.setOnShown { push(KeyCode.ENTER) }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/CollectionsBindingSet.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("CollectionsBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.IntegerBinding
import javafx.collections.ObservableSet

/** Generates a bidirectional binding between two instances of [ObservableSet]. */
inline fun <E> ObservableSet<E>.bindContentBidirectional(other: ObservableSet<E>): Unit =
    Bindings.bindContentBidirectional(this, other)

/** Remove a bidirectional binding between two instances of [ObservableSet]. */
inline fun <E> ObservableSet<E>.unbindContentBidirectional(other: ObservableSet<E>): Unit =
    Bindings.unbindContentBidirectional(this, other)

/** Generates a bidirectional binding between an [ObservableSet] and a [Set]. */
inline fun <E> Set<E>.bindContent(other: ObservableSet<E>): Unit = Bindings.bindContent(this, other)

/** Remove a bidirectional binding between an [ObservableSet] and a [Set]. */
inline fun <E> Set<E>.unbindContent(other: ObservableSet<E>): Unit = Bindings.unbindContent(this, other)

/** Creates a new [IntegerBinding] that contains the size [ObservableSet]. */
inline fun <E> ObservableSet<E>.size(): IntegerBinding = Bindings.size(this)

/** Creates a new [BooleanBinding] that holds `true` if a given [ObservableSet] is empty. */
inline val <E> ObservableSet<E>.isEmpty: BooleanBinding get() = Bindings.isEmpty(this)

/** Creates a new [BooleanBinding] that holds `true` if a given [ObservableSet] is not empty. */
inline val <E> ObservableSet<E>.isNotEmpty: BooleanBinding get() = Bindings.isNotEmpty(this)


<|start_filename|>ktfx-layouts/src/javafx/scene/control/KtfxMenuButton.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.MenuButton
import javafx.scene.control.MenuItem
import kotlin.contracts.ExperimentalContracts

/**
 * [MenuButton] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxMenuButton(text: String?, graphic: Node?) : MenuButton(text, graphic), MenuItemManager {

    final override fun <C : MenuItem> addChild(child: C): C = child.also { items + it }

    /** Call [MenuItemManager.menuItem] by string invocation. */
    inline operator fun String.invoke(
        graphic: Node? = null,
        configuration: (@KtfxLayoutDslMarker MenuItem).() -> Unit
    ): MenuItem = menuItem(this, graphic, configuration)
}


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_Tab.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.Event
import javafx.scene.control.Tab
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Tab.setOnSelectionChanged
 */
public inline fun Tab.onSelectionChanged(noinline action: (Event) -> Unit) {
    return setOnSelectionChanged(action)
}

/**
 * @see Tab.setOnClosed
 */
public inline fun Tab.onClosed(noinline action: (Event) -> Unit) {
    return setOnClosed(action)
}

/**
 * @see Tab.setOnCloseRequest
 */
public inline fun Tab.onCloseRequest(noinline action: (Event) -> Unit) {
    return setOnCloseRequest(action)
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_ColorPicker.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.ColorPicker
import javafx.scene.paint.Color
import javafx.scene.paint.Color.WHITE
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [ColorPicker] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.colorPicker(color: Color = WHITE): ColorPicker = colorPicker(color = color) {
}

/**
 * Create a [ColorPicker] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun colorPicker(
    color: Color = WHITE,
    configuration: (
        @KtfxLayoutDslMarker    
        ColorPicker
    ).() -> Unit
): ColorPicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ColorPicker(color)
    child.configuration()
    return child
}

/**
 * Add a [ColorPicker] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.colorPicker(
    color: Color = WHITE,
    configuration: (
        @KtfxLayoutDslMarker    
        ColorPicker
    ).() -> Unit
): ColorPicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ColorPicker(color)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [ColorPicker].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledColorPicker(
    color: Color = WHITE,
    vararg styleClass: String,
    id: String? = null
): ColorPicker = styledColorPicker(color = color, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [ColorPicker] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledColorPicker(
    color: Color = WHITE,
    vararg styleClass: String,
    id: String? = null
): ColorPicker = styledColorPicker(color = color, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [ColorPicker] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledColorPicker(
    color: Color = WHITE,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker ColorPicker).() -> Unit
): ColorPicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ColorPicker(color)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [ColorPicker] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledColorPicker(
    color: Color = WHITE,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker ColorPicker).() -> Unit
): ColorPicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ColorPicker(color)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/media/MediaViewTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.media.MediaView
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class MediaViewTest : LayoutsTest<KtfxPane, MediaView>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = mediaView { }
    override fun KtfxPane.child2() = mediaView()
    override fun KtfxPane.child3() = mediaView { }

    override fun MediaView.testDefaultValues() {
        assertNull(mediaPlayer)
    }
}

<|start_filename|>ktfx-listeners/src/javafx/stage/Window.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.stage.Window

/** Registers an event filter to this node. */
inline fun <E : Event> Window.eventFilter(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventFilter(type, it) }

/** Registers an event handler to this node. */
inline fun <E : Event> Window.eventHandler(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventHandler(type, it) }


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_ClosePath.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.ClosePath
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [ClosePath] to this manager.
 *
 * @return the control added.
 */
public fun PathElementManager.closePath(): ClosePath = closePath() { }

/**
 * Create a [ClosePath] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun closePath(configuration: (@KtfxLayoutDslMarker ClosePath).() -> Unit): ClosePath {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ClosePath()
    child.configuration()
    return child
}

/**
 * Add a [ClosePath] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun PathElementManager.closePath(
    configuration: (@KtfxLayoutDslMarker ClosePath).() ->
    Unit
): ClosePath {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ClosePath()
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/NodeTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.Node
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseNodeTest

class NodeTest : BaseNodeTest() {

    override fun Node.callOnDragEntered(action: (DragEvent) -> Unit) =
        onDragEntered(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnDragExited(action: (DragEvent) -> Unit) =
        onDragExited(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnDragOver(action: (DragEvent) -> Unit) =
        onDragOver(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnDragDropped(action: (DragEvent) -> Unit) =
        onDragDropped(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnDragDone(action: (DragEvent) -> Unit) =
        onDragDone(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnContextMenuRequested(action: (ContextMenuEvent) -> Unit) =
        onContextMenuRequested(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMouseClicked(action: (MouseEvent) -> Unit) =
        onMouseClicked(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMouseDragged(action: (MouseEvent) -> Unit) =
        onMouseDragged(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMouseEntered(action: (MouseEvent) -> Unit) =
        onMouseEntered(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMouseExited(action: (MouseEvent) -> Unit) =
        onMouseExited(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMouseMoved(action: (MouseEvent) -> Unit) =
        onMouseMoved(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMousePressed(action: (MouseEvent) -> Unit) =
        onMousePressed(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMouseReleased(action: (MouseEvent) -> Unit) =
        onMouseReleased(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnDragDetected(action: (MouseEvent) -> Unit) =
        onDragDetected(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMouseDragOver(action: (MouseDragEvent) -> Unit) =
        onMouseDragOver(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMouseDragReleased(action: (MouseDragEvent) -> Unit) =
        onMouseDragReleased(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMouseDragEntered(action: (MouseDragEvent) -> Unit) =
        onMouseDragEntered(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnMouseDragExited(action: (MouseDragEvent) -> Unit) =
        onMouseDragExited(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnScrollStarted(action: (ScrollEvent) -> Unit) =
        onScrollStarted(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnScroll(action: (ScrollEvent) -> Unit) =
        onScroll(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnScrollFinished(action: (ScrollEvent) -> Unit) =
        onScrollFinished(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnRotationStarted(action: (RotateEvent) -> Unit) =
        onRotationStarted(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnRotate(action: (RotateEvent) -> Unit) =
        onRotate(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnRotationFinished(action: (RotateEvent) -> Unit) =
        onRotationFinished(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnZoomStarted(action: (ZoomEvent) -> Unit) =
        onZoomStarted(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnZoom(action: (ZoomEvent) -> Unit) =
        onZoom(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnZoomFinished(action: (ZoomEvent) -> Unit) =
        onZoomFinished(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnSwipeUp(action: (SwipeEvent) -> Unit) =
        onSwipeUp(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnSwipeDown(action: (SwipeEvent) -> Unit) =
        onSwipeDown(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnSwipeRight(action: (SwipeEvent) -> Unit) =
        onSwipeRight(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnSwipeLeft(action: (SwipeEvent) -> Unit) =
        onSwipeLeft(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnTouchPressed(action: (TouchEvent) -> Unit) =
        onTouchPressed(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnTouchMoved(action: (TouchEvent) -> Unit) =
        onTouchMoved(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnTouchReleased(action: (TouchEvent) -> Unit) =
        onTouchReleased(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnTouchStationary(action: (TouchEvent) -> Unit) =
        onTouchStationary(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnKeyPressed(action: (KeyEvent) -> Unit) =
        onKeyPressed(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnKeyReleased(action: (KeyEvent) -> Unit) =
        onKeyReleased(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnKeyTyped(action: (KeyEvent) -> Unit) =
        onKeyTyped(Dispatchers.Unconfined) { action(it) }

    override fun Node.callOnInputMethodTextChanged(action: (InputMethodEvent) -> Unit) =
        onInputMethodTextChanged(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_MediaView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.media.MediaErrorEvent
import javafx.scene.media.MediaView
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see MediaView.setOnError
 */
public inline fun MediaView.onError(noinline action: (MediaErrorEvent) -> Unit) {
    return setOnError(action)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/MenuItemTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.MenuItem
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class MenuItemTest : LayoutsTest<KtfxMenu, MenuItem>() {

    override fun manager() = KtfxMenu("", null)
    override fun KtfxMenu.childCount() = items.size
    override fun child1() = menuItem { }
    override fun KtfxMenu.child2() = menuItem()
    override fun KtfxMenu.child3() = menuItem { }

    override fun MenuItem.testDefaultValues() {
        assertNull(text)
        assertNull(graphic)
    }
}

<|start_filename|>testing/ruleset/src/com/hendraanggrian/ktfx/test/RuleTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import com.google.common.truth.Truth.assertThat
import com.pinterest.ktlint.core.LintError
import com.pinterest.ktlint.core.Rule
import com.pinterest.ktlint.test.lint

/** For testing single rule, not multiple rules at the same time. */
interface RuleTest {

    val rule: Rule

    fun assertRule(vararg expectedErrors: Triple<Int, Int, String>, code: () -> String) {
        assertThat(rule.lint(code().trimIndent()))
            .containsExactly(*expectedErrors.map { LintError(it.first, it.second, rule.id, it.third) }.toTypedArray())
    }

    fun lintErrorOf(line: Int, col: Int, message: String) = Triple(line, col, message)
}

<|start_filename|>rulesets/non-commons/tests/src/com/hendraanggrian/ktfx/rules/PredefinedPackageRuleTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.hendraanggrian.ktfx.test.RuleTest
import kotlin.test.Test

class PredefinedPackageRuleTest : RuleTest {
    override val rule = PredefinedPackageRule()

    @Test
    fun correct() = assertRule {
        """
            package ktfx.coroutines
        """
    }

    @Test
    fun wrong() = assertRule(
        lintErrorOf(1, 9, "Illegal package name.")
    ) {
        """
            package ktfx.coroutiness
        """
    }
}

<|start_filename|>ktfx-commons/src/ktfx/inputs/KeyCombination.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.inputs

import javafx.scene.input.KeyCharacterCombination
import javafx.scene.input.KeyCode
import javafx.scene.input.KeyCodeCombination
import javafx.scene.input.KeyCombination

/** Constructs a combination based on modifier and main character. */
inline operator fun KeyCombination.Modifier.plus(character: String): KeyCharacterCombination =
    KeyCharacterCombination(character, this)

/** Constructs a combination based on modifier and main code. */
inline operator fun KeyCombination.Modifier.plus(code: KeyCode): KeyCodeCombination = KeyCodeCombination(code, this)

/** Constructs a combination based on modifier and main code. */
inline operator fun KeyCode.plus(modifier: KeyCombination.Modifier): KeyCodeCombination = modifier + this


<|start_filename|>ktfx-layouts/src/javafx/scene/control/KtfxTabPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.Tab
import javafx.scene.control.TabPane
import kotlin.contracts.ExperimentalContracts

/**
 * [TabPane] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxTabPane : TabPane(), TabManager {

    final override fun <C : Tab> addChild(child: C): C = child.also { tabs += it }

    /** Call [TabManager.tab] by string invocation. */
    inline operator fun String.invoke(
        graphic: Node? = null,
        configuration: (@KtfxLayoutDslMarker KtfxTab).() -> Unit
    ): Tab = tab(this, graphic, configuration)
}


<|start_filename|>ktfx-commons/src/ktfx/controls/TableColumns.kt<|end_filename|>
@file:OptIn(ExperimentalContracts::class)

package ktfx.controls

import javafx.scene.control.TableColumn
import javafx.scene.control.TableView
import javafx.scene.control.TreeTableColumn
import javafx.scene.control.TreeTableView
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/** Delimits table column DSL configuration. */
@DslMarker
@Target(AnnotationTarget.CLASS)
annotation class TableColumnDslMarker

/**
 * Configure [TableView] columns.
 * @param configuration the configuration block.
 */
fun <S> TableView<S>.columns(configuration: TableColumnScope<S>.() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    val columns2 = columns // explicit ref to avoid ambiguous label
    object : TableColumnScope<S> {
        override val columns: MutableCollection<TableColumn<S, *>> get() = columns2
    }.configuration()
}

/**
 * Configure [TableColumn] columns, essentially enabling multi-line column.
 * @param configuration the configuration block.
 */
fun <S> TableColumn<S, *>.columns(configuration: TableColumnScope<S>.() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    val columns2 = columns // explicit ref to avoid ambiguous label
    object : TableColumnScope<S> {
        override val columns: MutableCollection<TableColumn<S, *>> get() = columns2
    }.configuration()
}

/**
 * Configure [TreeTableView] columns.
 * @param configuration the configuration block.
 */
fun <S> TreeTableView<S>.columns(configuration: TreeTableColumnScope<S>.() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    val columns2 = columns // explicit ref to avoid ambiguous label
    object : TreeTableColumnScope<S> {
        override val columns: MutableCollection<TreeTableColumn<S, *>> get() = columns2
    }.configuration()
}

/**
 * Configure [TreeTableColumn] columns, essentially enabling multi-line column.
 * @param configuration the configuration block.
 */
fun <S> TreeTableColumn<S, *>.columns(configuration: TreeTableColumnScope<S>.() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    val columns2 = columns // explicit ref to avoid ambiguous label
    object : TreeTableColumnScope<S> {
        override val columns: MutableCollection<TreeTableColumn<S, *>> get() = columns2
    }.configuration()
}

/** [TableColumn] configurator interface. */
@TableColumnDslMarker
interface TableColumnScope<S> {

    /** Collection of columns within this scope. */
    val columns: MutableCollection<TableColumn<S, *>>

    /** Add a default column using [text], returning the column added. */
    fun <T> append(
        text: String? = null
    ): TableColumn<S, T> = TableColumn<S, T>(text).also { columns += it }

    /** Add a column using [text] and [configuration] block, returning the column added. */
    fun <T> append(
        text: String? = null,
        configuration: TableColumn<S, T>.() -> Unit
    ): TableColumn<S, T> {
        val column = TableColumn<S, T>(text).apply(configuration)
        columns += column
        return column
    }

    /** Add a column using receiver and [configuration] block, returning the column added. */
    operator fun <T> String.invoke(
        configuration: TableColumn<S, T>.() -> Unit
    ): TableColumn<S, T> = append(this, configuration)
}

/** [TreeTableColumn] configurator interface. */
@TableColumnDslMarker
interface TreeTableColumnScope<S> {

    /** Collection of columns within this scope. */
    val columns: MutableCollection<TreeTableColumn<S, *>>

    /** Add a default column using [text], returning the column added. */
    fun <T> append(
        text: String? = null
    ): TreeTableColumn<S, T> = TreeTableColumn<S, T>(text).also { columns += it }

    /** Add a column using [text] and [configuration] block, returning the column added. */
    fun <T> append(
        text: String? = null,
        configuration: TreeTableColumn<S, T>.() -> Unit
    ): TreeTableColumn<S, T> = TreeTableColumn<S, T>(text).also {
        it.configuration()
        columns += it
    }

    /** Add a column using receiver and [configuration] block, returning the column added. */
    operator fun <T> String.invoke(
        configuration: TreeTableColumn<S, T>.() -> Unit
    ): TreeTableColumn<S, T> = append(this, configuration)
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXTabPaneTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTabPane
import ktfx.layouts.KtfxPane
import ktfx.layouts.tab
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.Test
import kotlin.test.assertEquals

class JFXTabPaneTest : LayoutsTest<KtfxPane, JFXTabPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxTabPane { }
    override fun KtfxPane.child2() = jfxTabPane()
    override fun KtfxPane.child3() = jfxTabPane { }

    @Test
    fun stringInvocation() {
        jfxTabPane {
            tab("Tab 1")
            "Tab 2" {
            }
            assertEquals(2, tabs.size)
        }
    }
}

<|start_filename|>buildSrc/src/dependencies.kt<|end_filename|>
internal typealias Plugins = org.gradle.plugin.use.PluginDependenciesSpec
internal typealias Dependencies = org.gradle.api.artifacts.dsl.DependencyHandler

const val VERSION_JAVAFX_PLUGIN = "0.0.10"
val Dependencies.javafx get() = "org.openjfx:javafx-plugin:$VERSION_JAVAFX_PLUGIN"
val Plugins.javafx get() = id("org.openjfx.javafxplugin")

const val VERSION_KOTLIN = "1.5.21"
const val VERSION_COROUTINES = "1.5.1"
val Dependencies.dokka get() = "org.jetbrains.dokka:dokka-gradle-plugin:1.5.0"
val Plugins.dokka get() = id("org.jetbrains.dokka")
fun Dependencies.kotlinx(module: String, version: String? = null) =
    "org.jetbrains.kotlinx:kotlinx-$module${version?.let { ":$it" }.orEmpty()}"

val Dependencies.`git-publish` get() = "org.ajoberstar:gradle-git-publish:3.0.0"
val Plugins.`git-publish` get() = id("org.ajoberstar.git-publish")

const val VERSION_COMMONS_LANG = "3.11"
fun Dependencies.apache(module: String, version: String): String {
    require('-' in module) { "Module must contain `-` (e.g.: commons-lang, commons-math)." }
    return "org.apache.${module.split('-').first()}:$module:$version"
}

fun Dependencies.controlsfx() = "org.controlsfx:controlsfx:11.1.0"
fun Dependencies.jfoenix() = "com.jfoenix:jfoenix:9.0.10"

const val VERSION_TRUTH = "1.1.3"
fun Dependencies.google(repo: String? = null, module: String, version: String) =
    "com.google${repo?.let { ".$it" }.orEmpty()}:$module:$version"

fun Dependencies.kotlinpoetKtx() = "com.hendraanggrian:kotlinpoet-ktx:0.1-SNAPSHOT"

const val VERSION_MONOCLE = "jdk-11+26"
fun Dependencies.testFx(module: String, version: String = "4.0.16-alpha") = "org.testfx:$module:$version"
fun Dependencies.junit() = "junit:junit:4.13-beta-3"

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/BaseSceneTest.kt<|end_filename|>
package javafx.scene

import com.google.common.truth.Truth.assertThat
import com.hendraanggrian.ktfx.test.FakeEventTarget
import com.hendraanggrian.ktfx.test.FakePickResult
import com.hendraanggrian.ktfx.test.assertFakeDragEvent
import com.hendraanggrian.ktfx.test.assertFakeKeyEvent
import com.hendraanggrian.ktfx.test.assertFakeMouseDragEvent
import com.hendraanggrian.ktfx.test.assertFakeMouseEvent
import com.hendraanggrian.ktfx.test.assertFakeRotateEvent
import com.hendraanggrian.ktfx.test.assertFakeScrollEvent
import com.hendraanggrian.ktfx.test.assertFakeSwipeEvent
import com.hendraanggrian.ktfx.test.assertFakeTouchEvent
import com.hendraanggrian.ktfx.test.assertFakeZoomEvent
import com.hendraanggrian.ktfx.test.fakeDragEventOf
import com.hendraanggrian.ktfx.test.fakeKeyEventOf
import com.hendraanggrian.ktfx.test.fakeMouseDragEventOf
import com.hendraanggrian.ktfx.test.fakeMouseEventOf
import com.hendraanggrian.ktfx.test.fakeRotateEventOf
import com.hendraanggrian.ktfx.test.fakeScrollEventOf
import com.hendraanggrian.ktfx.test.fakeSwipeEventOf
import com.hendraanggrian.ktfx.test.fakeTouchEventOf
import com.hendraanggrian.ktfx.test.fakeZoomEventOf
import com.hendraanggrian.ktfx.test.initToolkit
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent
import javafx.scene.layout.Pane
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse

abstract class BaseSceneTest {
    private lateinit var scene: Scene

    abstract fun Scene.callOnMouseClicked(action: (MouseEvent) -> Unit)
    abstract fun Scene.callOnMouseDragged(action: (MouseEvent) -> Unit)
    abstract fun Scene.callOnMouseEntered(action: (MouseEvent) -> Unit)
    abstract fun Scene.callOnMouseExited(action: (MouseEvent) -> Unit)
    abstract fun Scene.callOnMouseMoved(action: (MouseEvent) -> Unit)
    abstract fun Scene.callOnMousePressed(action: (MouseEvent) -> Unit)
    abstract fun Scene.callOnMouseReleased(action: (MouseEvent) -> Unit)
    abstract fun Scene.callOnDragDetected(action: (MouseEvent) -> Unit)
    abstract fun Scene.callOnMouseDragOver(action: (MouseDragEvent) -> Unit)
    abstract fun Scene.callOnMouseDragReleased(action: (MouseDragEvent) -> Unit)
    abstract fun Scene.callOnMouseDragEntered(action: (MouseDragEvent) -> Unit)
    abstract fun Scene.callOnMouseDragExited(action: (MouseDragEvent) -> Unit)
    abstract fun Scene.callOnScrollStarted(action: (ScrollEvent) -> Unit)
    abstract fun Scene.callOnScroll(action: (ScrollEvent) -> Unit)
    abstract fun Scene.callOnScrollFinished(action: (ScrollEvent) -> Unit)
    abstract fun Scene.callOnRotationStarted(action: (RotateEvent) -> Unit)
    abstract fun Scene.callOnRotate(action: (RotateEvent) -> Unit)
    abstract fun Scene.callOnRotationFinished(action: (RotateEvent) -> Unit)
    abstract fun Scene.callOnZoomStarted(action: (ZoomEvent) -> Unit)
    abstract fun Scene.callOnZoom(action: (ZoomEvent) -> Unit)
    abstract fun Scene.callOnZoomFinished(action: (ZoomEvent) -> Unit)
    abstract fun Scene.callOnSwipeUp(action: (SwipeEvent) -> Unit)
    abstract fun Scene.callOnSwipeDown(action: (SwipeEvent) -> Unit)
    abstract fun Scene.callOnSwipeLeft(action: (SwipeEvent) -> Unit)
    abstract fun Scene.callOnSwipeRight(action: (SwipeEvent) -> Unit)
    abstract fun Scene.callOnTouchPressed(action: (TouchEvent) -> Unit)
    abstract fun Scene.callOnTouchMoved(action: (TouchEvent) -> Unit)
    abstract fun Scene.callOnTouchReleased(action: (TouchEvent) -> Unit)
    abstract fun Scene.callOnTouchStationary(action: (TouchEvent) -> Unit)
    abstract fun Scene.callOnDragEntered(action: (DragEvent) -> Unit)
    abstract fun Scene.callOnDragExited(action: (DragEvent) -> Unit)
    abstract fun Scene.callOnDragOver(action: (DragEvent) -> Unit)
    abstract fun Scene.callOnDragDropped(action: (DragEvent) -> Unit)
    abstract fun Scene.callOnDragDone(action: (DragEvent) -> Unit)
    abstract fun Scene.callOnKeyPressed(action: (KeyEvent) -> Unit)
    abstract fun Scene.callOnKeyReleased(action: (KeyEvent) -> Unit)
    abstract fun Scene.callOnKeyTyped(action: (KeyEvent) -> Unit)
    abstract fun Scene.callOnInputMethodTextChanged(action: (InputMethodEvent) -> Unit)
    abstract fun Scene.callOnContextMenuRequested(action: (ContextMenuEvent) -> Unit)

    @BeforeTest
    fun onCreate() {
        initToolkit()
        scene = Scene(Pane())
    }

    @Test
    fun onMouseClicked() {
        scene.callOnMouseClicked { assertFakeMouseEvent(it, MouseEvent.MOUSE_CLICKED) }
        scene.onMouseClicked.handle(fakeMouseEventOf(MouseEvent.MOUSE_CLICKED))
    }

    @Test
    fun onMouseDragged() {
        scene.callOnMouseDragged { assertFakeMouseEvent(it, MouseEvent.MOUSE_DRAGGED) }
        scene.onMouseDragged.handle(fakeMouseEventOf(MouseEvent.MOUSE_DRAGGED))
    }

    @Test
    fun onMouseEntered() {
        scene.callOnMouseEntered { assertFakeMouseEvent(it, MouseEvent.MOUSE_ENTERED) }
        scene.onMouseEntered.handle(fakeMouseEventOf(MouseEvent.MOUSE_ENTERED))
    }

    @Test
    fun onMouseExited() {
        scene.callOnMouseExited { assertFakeMouseEvent(it, MouseEvent.MOUSE_EXITED) }
        scene.onMouseExited.handle(fakeMouseEventOf(MouseEvent.MOUSE_EXITED))
    }

    @Test
    fun onMouseMoved() {
        scene.callOnMouseMoved { assertFakeMouseEvent(it, MouseEvent.MOUSE_MOVED) }
        scene.onMouseMoved.handle(fakeMouseEventOf(MouseEvent.MOUSE_MOVED))
    }

    @Test
    fun onMousePressed() {
        scene.callOnMousePressed { assertFakeMouseEvent(it, MouseEvent.MOUSE_PRESSED) }
        scene.onMousePressed.handle(fakeMouseEventOf(MouseEvent.MOUSE_PRESSED))
    }

    @Test
    fun onMouseReleased() {
        scene.callOnMouseReleased { assertFakeMouseEvent(it, MouseEvent.MOUSE_RELEASED) }
        scene.onMouseReleased.handle(fakeMouseEventOf(MouseEvent.MOUSE_RELEASED))
    }

    @Test
    fun onDragDetected() {
        scene.callOnDragDetected { assertFakeMouseEvent(it, MouseEvent.DRAG_DETECTED) }
        scene.onDragDetected.handle(fakeMouseEventOf(MouseEvent.DRAG_DETECTED))
    }

    @Test
    fun onMouseDragOver() {
        scene.callOnMouseDragOver { assertFakeMouseDragEvent(it, MouseDragEvent.MOUSE_DRAG_OVER) }
        scene.onMouseDragOver.handle(fakeMouseDragEventOf(MouseDragEvent.MOUSE_DRAG_OVER))
    }

    @Test
    fun onMouseDragReleased() {
        scene.callOnMouseDragReleased { assertFakeMouseDragEvent(it, MouseDragEvent.MOUSE_DRAG_RELEASED) }
        scene.onMouseDragReleased.handle(fakeMouseDragEventOf(MouseDragEvent.MOUSE_DRAG_RELEASED))
    }

    @Test
    fun onMouseDragEntered() {
        scene.callOnMouseDragEntered { assertFakeMouseDragEvent(it, MouseDragEvent.MOUSE_DRAG_ENTERED) }
        scene.onMouseDragEntered.handle(fakeMouseDragEventOf(MouseDragEvent.MOUSE_DRAG_ENTERED))
    }

    @Test
    fun onMouseDragExited() {
        scene.callOnMouseDragExited { assertFakeMouseDragEvent(it, MouseDragEvent.MOUSE_DRAG_EXITED) }
        scene.onMouseDragExited.handle(fakeMouseDragEventOf(MouseDragEvent.MOUSE_DRAG_EXITED))
    }

    @Test
    fun onScrollStarted() {
        scene.callOnScrollStarted { assertFakeScrollEvent(it, ScrollEvent.SCROLL_STARTED) }
        scene.onScrollStarted.handle(fakeScrollEventOf(ScrollEvent.SCROLL_STARTED))
    }

    @Test
    fun onScroll() {
        scene.callOnScroll { assertFakeScrollEvent(it, ScrollEvent.SCROLL) }
        scene.onScroll.handle(fakeScrollEventOf(ScrollEvent.SCROLL))
    }

    @Test
    fun onScrollFinished() {
        scene.callOnScrollFinished { assertFakeScrollEvent(it, ScrollEvent.SCROLL_FINISHED) }
        scene.onScrollFinished.handle(fakeScrollEventOf(ScrollEvent.SCROLL_FINISHED))
    }

    @Test
    fun onRotateStarted() {
        scene.callOnRotationStarted { assertFakeRotateEvent(it, RotateEvent.ROTATION_STARTED) }
        scene.onRotationStarted.handle(fakeRotateEventOf(RotateEvent.ROTATION_STARTED))
    }

    @Test
    fun onRotate() {
        scene.callOnRotate { assertFakeRotateEvent(it, RotateEvent.ROTATE) }
        scene.onRotate.handle(fakeRotateEventOf(RotateEvent.ROTATE))
    }

    @Test
    fun onRotateFinished() {
        scene.callOnRotationFinished { assertFakeRotateEvent(it, RotateEvent.ROTATION_FINISHED) }
        scene.onRotationFinished.handle(fakeRotateEventOf(RotateEvent.ROTATION_FINISHED))
    }

    @Test
    fun onZoomStarted() {
        scene.callOnZoomStarted { assertFakeZoomEvent(it, ZoomEvent.ZOOM_STARTED) }
        scene.onZoomStarted.handle(fakeZoomEventOf(ZoomEvent.ZOOM_STARTED))
    }

    @Test
    fun onZoom() {
        scene.callOnZoom { assertFakeZoomEvent(it, ZoomEvent.ZOOM) }
        scene.onZoom.handle(fakeZoomEventOf(ZoomEvent.ZOOM))
    }

    @Test
    fun onZoomFinished() {
        scene.callOnZoomFinished { assertFakeZoomEvent(it, ZoomEvent.ZOOM_FINISHED) }
        scene.onZoomFinished.handle(fakeZoomEventOf(ZoomEvent.ZOOM_FINISHED))
    }

    @Test
    fun onSwipeUp() {
        scene.callOnSwipeUp { assertFakeSwipeEvent(it, SwipeEvent.SWIPE_UP) }
        scene.onSwipeUp.handle(fakeSwipeEventOf(SwipeEvent.SWIPE_UP))
    }

    @Test
    fun onSwipeDown() {
        scene.callOnSwipeDown { assertFakeSwipeEvent(it, SwipeEvent.SWIPE_DOWN) }
        scene.onSwipeDown.handle(fakeSwipeEventOf(SwipeEvent.SWIPE_DOWN))
    }

    @Test
    fun onSwipeRight() {
        scene.callOnSwipeRight { assertFakeSwipeEvent(it, SwipeEvent.SWIPE_RIGHT) }
        scene.onSwipeRight.handle(fakeSwipeEventOf(SwipeEvent.SWIPE_RIGHT))
    }

    @Test
    fun onSwipeLeft() {
        scene.callOnSwipeLeft { assertFakeSwipeEvent(it, SwipeEvent.SWIPE_LEFT) }
        scene.onSwipeLeft.handle(fakeSwipeEventOf(SwipeEvent.SWIPE_LEFT))
    }

    @Test
    fun onTouchPressed() {
        scene.callOnTouchPressed { assertFakeTouchEvent(it, TouchEvent.TOUCH_PRESSED) }
        scene.onTouchPressed.handle(fakeTouchEventOf(TouchEvent.TOUCH_PRESSED))
    }

    @Test
    fun onTouchMoved() {
        scene.callOnTouchMoved { assertFakeTouchEvent(it, TouchEvent.TOUCH_MOVED) }
        scene.onTouchMoved.handle(fakeTouchEventOf(TouchEvent.TOUCH_MOVED))
    }

    @Test
    fun onTouchReleased() {
        scene.callOnTouchReleased { assertFakeTouchEvent(it, TouchEvent.TOUCH_RELEASED) }
        scene.onTouchReleased.handle(fakeTouchEventOf(TouchEvent.TOUCH_RELEASED))
    }

    @Test
    fun onTouchStationary() {
        scene.callOnTouchStationary { assertFakeTouchEvent(it, TouchEvent.TOUCH_STATIONARY) }
        scene.onTouchStationary.handle(fakeTouchEventOf(TouchEvent.TOUCH_STATIONARY))
    }

    @Test
    fun onDragEntered() {
        scene.callOnDragEntered { assertFakeDragEvent(it, DragEvent.DRAG_ENTERED) }
        scene.onDragEntered.handle(fakeDragEventOf(DragEvent.DRAG_ENTERED))
    }

    @Test
    fun onDragExited() {
        scene.callOnDragExited { assertFakeDragEvent(it, DragEvent.DRAG_EXITED) }
        scene.onDragExited.handle(fakeDragEventOf(DragEvent.DRAG_EXITED))
    }

    @Test
    fun onDragOver() {
        scene.callOnDragOver { assertFakeDragEvent(it, DragEvent.DRAG_OVER) }
        scene.onDragOver.handle(fakeDragEventOf(DragEvent.DRAG_OVER))
    }

    @Test
    fun onDragDropped() {
        scene.callOnDragDropped { assertFakeDragEvent(it, DragEvent.DRAG_DROPPED) }
        scene.onDragDropped.handle(fakeDragEventOf(DragEvent.DRAG_DROPPED))
    }

    @Test
    fun onDragDone() {
        scene.callOnDragDone { assertFakeDragEvent(it, DragEvent.DRAG_DONE) }
        scene.onDragDone.handle(fakeDragEventOf(DragEvent.DRAG_DONE))
    }

    @Test
    fun onKeyPressed() {
        scene.callOnKeyPressed { assertFakeKeyEvent(it, KeyEvent.KEY_PRESSED) }
        scene.onKeyPressed.handle(fakeKeyEventOf(KeyEvent.KEY_PRESSED))
    }

    @Test
    fun onKeyReleased() {
        scene.callOnKeyReleased { assertFakeKeyEvent(it, KeyEvent.KEY_RELEASED) }
        scene.onKeyReleased.handle(fakeKeyEventOf(KeyEvent.KEY_RELEASED))
    }

    @Test
    fun onKeyTyped() {
        scene.callOnKeyTyped { assertFakeKeyEvent(it, KeyEvent.KEY_TYPED) }
        scene.onKeyTyped.handle(fakeKeyEventOf(KeyEvent.KEY_TYPED))
    }

    @Test
    fun onInputMethodTextChanged() {
        scene.callOnInputMethodTextChanged {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED, it.eventType)
            assertThat(it.composed).isEmpty()
            assertEquals("Hello world", it.committed)
            assertEquals(0, it.caretPosition)
        }
        scene.onInputMethodTextChanged.handle(
            InputMethodEvent(
                this, FakeEventTarget, InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                listOf(), "Hello world", 0
            )
        )
    }

    @Test
    fun onContextMenuRequested() {
        scene.callOnContextMenuRequested {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(ContextMenuEvent.CONTEXT_MENU_REQUESTED, it.eventType)
            assertEquals(0.0, it.x)
            assertEquals(0.0, it.y)
            assertEquals(0.0, it.sceneX)
            assertEquals(0.0, it.sceneY)
            assertFalse(it.isKeyboardTrigger)
            assertEquals(FakePickResult, it.pickResult)
        }
        scene.onContextMenuRequested.handle(
            ContextMenuEvent(
                this, FakeEventTarget, ContextMenuEvent.CONTEXT_MENU_REQUESTED,
                0.0, 0.0, 0.0, 0.0,
                false, FakePickResult
            )
        )
    }
}

<|start_filename|>ktfx-layouts/src/javafx/scene/control/KtfxSplitPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.SplitPane
import kotlin.contracts.ExperimentalContracts

/**
 * [SplitPane] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxSplitPane : SplitPane(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { items += it }
}


<|start_filename|>testing/ruleset/build.gradle.kts<|end_filename|>
plugins {
    kotlin("jvm")
}

sourceSets {
    main {
        java.srcDir("src")
    }
}

dependencies {
    implementation(kotlin("stdlib", VERSION_KOTLIN))
    implementation(kotlin("test-junit", VERSION_KOTLIN))
    implementation(google("truth", "truth", VERSION_TRUTH))
    implementation(ktlint("core"))
    implementation(ktlint("test"))
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/LabelTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.Label
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class LabelTest : LayoutsTest<KtfxPane, Label>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = label { }
    override fun KtfxPane.child2() = label()
    override fun KtfxPane.child3() = label { }

    override fun Label.testDefaultValues() {
        assertNull(text)
        assertNull(graphic)
    }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/controls/GeometryTest.kt<|end_filename|>
package ktfx.controls

import javafx.geometry.HPos
import javafx.geometry.Orientation
import javafx.geometry.Pos
import javafx.geometry.Side
import javafx.geometry.VPos
import kotlin.test.Test
import kotlin.test.assertSame

class GeometryTest {

    @Test
    fun pos() {
        assertSame(Pos.TOP_LEFT, TOP_LEFT)
        assertSame(Pos.TOP_CENTER, TOP)
        assertSame(Pos.TOP_RIGHT, TOP_RIGHT)
        assertSame(Pos.CENTER_LEFT, LEFT)
        assertSame(Pos.CENTER, CENTER)
        assertSame(Pos.CENTER_RIGHT, RIGHT)
        assertSame(Pos.BOTTOM_LEFT, BOTTOM_LEFT)
        assertSame(Pos.BOTTOM_CENTER, BOTTOM)
        assertSame(Pos.BOTTOM_RIGHT, BOTTOM_RIGHT)
        assertSame(Pos.BASELINE_LEFT, BASELINE_LEFT)
        assertSame(Pos.BASELINE_CENTER, BASELINE)
        assertSame(Pos.BASELINE_RIGHT, BASELINE_RIGHT)
    }

    @Test
    fun hpos() {
        assertSame(HPos.LEFT, H_LEFT)
        assertSame(HPos.CENTER, H_CENTER)
        assertSame(HPos.RIGHT, H_RIGHT)
    }

    @Test
    fun vpos() {
        assertSame(VPos.TOP, V_TOP)
        assertSame(VPos.CENTER, V_CENTER)
        assertSame(VPos.BOTTOM, V_BOTTOM)
        assertSame(VPos.BASELINE, V_BASELINE)
    }

    @Test
    fun orientation() {
        assertSame(Orientation.HORIZONTAL, HORIZONTAL)
        assertSame(Orientation.VERTICAL, VERTICAL)
    }

    @Test
    fun side() {
        assertSame(Side.TOP, SIDE_TOP)
        assertSame(Side.BOTTOM, SIDE_BOTTOM)
        assertSame(Side.LEFT, SIDE_LEFT)
        assertSame(Side.RIGHT, SIDE_RIGHT)
    }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/stage/PopupWindowTest.kt<|end_filename|>
package ktfx.listeners

import javafx.event.Event
import javafx.stage.BasePopupWindowTest
import javafx.stage.PopupWindow

class PopupWindowTest : BasePopupWindowTest() {

    override fun PopupWindow.callOnAutoHide(action: (Event) -> Unit) = onAutoHide(action)
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/MenuItemTest.kt<|end_filename|>
package ktfx.listeners

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.MenuItem
import com.hendraanggrian.ktfx.test.BaseMenuItemTest

class MenuItemTest : BaseMenuItemTest() {

    override fun MenuItem.callOnAction(action: (ActionEvent) -> Unit) = onAction(action)
    override fun MenuItem.callOnMenuValidation(action: (Event) -> Unit) = onMenuValidation(action)
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_QuadCurveTo.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.QuadCurveTo
import kotlin.Double
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [QuadCurveTo] to this manager.
 *
 * @return the control added.
 */
public fun PathElementManager.quadCurveTo(
    controlX: Double = 0.0,
    controlY: Double = 0.0,
    x: Double = 0.0,
    y: Double = 0.0
): QuadCurveTo = quadCurveTo(controlX = controlX, controlY = controlY, x = x, y = y) { }

/**
 * Create a [QuadCurveTo] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun quadCurveTo(
    controlX: Double = 0.0,
    controlY: Double = 0.0,
    x: Double = 0.0,
    y: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker QuadCurveTo).() -> Unit
): QuadCurveTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = QuadCurveTo(controlX, controlY, x, y)
    child.configuration()
    return child
}

/**
 * Add a [QuadCurveTo] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun PathElementManager.quadCurveTo(
    controlX: Double = 0.0,
    controlY: Double = 0.0,
    x: Double = 0.0,
    y: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker QuadCurveTo).() -> Unit
): QuadCurveTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = QuadCurveTo(controlX, controlY, x, y)
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-listeners/src/javafx/scene/control/MenuItem.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.scene.control.MenuItem

/** Registers an event handler to this [MenuItem]. */
inline fun <E : Event> MenuItem.eventHandler(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventHandler(type, it) }


<|start_filename|>thirdparty/jfoenix-layouts/src/com/jfoenix/controls/KtfxJFXToolbar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXToolbar
import javafx.geometry.Insets
import javafx.scene.Node
import javafx.scene.layout.HBox
import javafx.scene.layout.Priority
import ktfx.layouts.NodeManager
import kotlin.contracts.ExperimentalContracts

/**
 * [JFXToolbar] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxJFXToolbar : JFXToolbar() {

    class HBoxConstraints @PublishedApi internal constructor(private val list: MutableList<Node>) : NodeManager {
        override fun <C : Node> addChild(child: C): C = child.also { list += it }

        /** Children horizontal grow priority in this layout. */
        inline var Node.hgrow: Priority?
            @JvmName("getHgrow2") get() = HBox.getHgrow(this)
            @JvmName("setHgrow2") set(value) = HBox.setHgrow(this, value)

        /** Configure [hgrow] fluidly. */
        fun <C : Node> C.hgrow(always: Boolean = true): C {
            hgrow = if (always) Priority.ALWAYS else Priority.NEVER
            return this
        }

        /** Children margin in this layout. */
        inline var Node.margin: Insets?
            @JvmName("getMargin2") get() = getMargin(this)
            @JvmName("setMargin2") set(value) = setMargin(this, value)

        /** Configure [margin] fluidly. */
        fun <C : Node> C.margin(insets: Insets): C {
            margin = insets
            return this
        }

        /** Clear children constraints. */
        @JvmName("clearConstraints2")
        inline fun Node.clearConstraints(): Unit = HBox.clearConstraints(this)
    }
}


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/layouts/LayoutsWriter.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.layouts

import com.hendraanggrian.kotlinpoet.FunSpecBuilder
import com.hendraanggrian.kotlinpoet.INLINE
import com.hendraanggrian.kotlinpoet.VARARG
import com.hendraanggrian.kotlinpoet.annotate
import com.hendraanggrian.kotlinpoet.asNullable
import com.hendraanggrian.kotlinpoet.buildFileSpec
import com.hendraanggrian.kotlinpoet.dsl.ParameterSpecHandlerScope
import com.hendraanggrian.kotlinpoet.lambdaBy
import com.squareup.kotlinpoet.asClassName
import com.hendraanggrian.ktfx.codegen.CONTRACT
import com.hendraanggrian.ktfx.codegen.DSL_MARKER
import com.hendraanggrian.ktfx.codegen.EXACTLY_ONCE
import com.hendraanggrian.ktfx.codegen.EXPERIMENTAL_CONTRACTS
import com.hendraanggrian.ktfx.codegen.OPT_IN
import com.hendraanggrian.ktfx.codegen.toString
import java.io.File

object LayoutsWriter {

    fun write(factory: LayoutsFactory) {
        println("Generating to ${factory.path}:")
        factory.entries.forEach { entry ->
            val filteredEntries = factory.entries.filter { it.kClass == entry.kClass }
            val fileName = when (filteredEntries.size) {
                1 -> entry.generatedName
                else -> "${entry.generatedName}${filteredEntries.indexOf(entry)}"
            }
            println(fileName)
            buildFileSpec(factory.packageName, fileName) {
                indentSize = 4
                annotations {
                    add<JvmMultifileClass>()
                    JvmName::class { addMember("%S", factory.className) }
                    OPT_IN { addMember("%T::class", EXPERIMENTAL_CONTRACTS) }
                }
                functions {
                    entry.managerClassNames.forEach { managerClassName ->
                        entry.functionName {
                            entry.typeVarNames.forEach { typeVariables += it }
                            receiver = managerClassName
                            kdoc += entry.getFileComment(add = true, styled = false, configured = false)
                            returns(entry.typeName, entry.getReturnsComment(add = true, styled = false))
                            parameters {
                                entry.parameters.forEach(::plusAssign)
                            }
                            appendLine(
                                "return ${entry.functionName}(${entry.parameters.toString(
                                    namedArgument = true, commaSuffix = false
                                )}) { }"
                            )
                        }
                    }
                    entry.fullManagerClassNames.forEach { managerClassName ->
                        entry.functionName {
                            entry.typeVarNames.forEach { typeVariables += it }
                            if (managerClassName != null) receiver = managerClassName
                            addModifiers(INLINE)
                            kdoc += entry.getFileComment(
                                add = managerClassName != null, styled = false, configured = true
                            )
                            returns(
                                entry.typeName, entry.getReturnsComment(add = managerClassName != null, styled = false)
                            )
                            parameters {
                                entry.parameters.forEach(::plusAssign)
                                configuration(entry)
                            }
                            contractln()
                            appendLine(
                                "val child = %T(${entry.parameters.toString(
                                    namedArgument = false, commaSuffix = false
                                )})", entry.customTypeName
                            )
                            appendLine("child.configuration()")
                            appendLine {
                                append("return ")
                                if (managerClassName != null) append("addChild(")
                                append("child")
                                if (managerClassName != null) append(")")
                            }
                        }
                    }
                    if (entry.supportStyledFunction) {
                        entry.fullManagerClassNames.forEach { managerClassName ->
                            entry.styledFunctionName {
                                entry.typeVarNames.forEach { typeVariables += it }
                                if (managerClassName != null) receiver = managerClassName
                                kdoc += entry.getFileComment(
                                    add = managerClassName != null, styled = true, configured = false
                                )
                                returns(
                                    entry.typeName,
                                    entry.getReturnsComment(add = managerClassName != null, styled = true)
                                )
                                parameters {
                                    entry.parameters.forEach(::plusAssign)
                                    styleClass()
                                    id()
                                }
                                appendLine(
                                    "return ${entry.styledFunctionName}(${entry.parameters.toString(
                                        namedArgument = true, commaSuffix = true
                                    )}styleClass = *styleClass, id = id) { }"
                                )
                            }
                        }
                        entry.fullManagerClassNames.forEach { managerClassName ->
                            entry.styledFunctionName {
                                entry.typeVarNames.forEach { typeVariables += it }
                                if (managerClassName != null) receiver = managerClassName
                                addModifiers(INLINE)
                                kdoc += entry.getFileComment(
                                    add = managerClassName != null, styled = true, configured = true
                                )
                                returns(
                                    entry.typeName,
                                    entry.getReturnsComment(add = managerClassName != null, styled = true)
                                )
                                parameters {
                                    entry.parameters.forEach(::plusAssign)
                                    styleClass()
                                    id()
                                    configuration(entry)
                                }
                                contractln()
                                appendLine(
                                    "val child = %T(${entry.parameters.toString(
                                        namedArgument = false, commaSuffix = false
                                    )})", entry.customTypeName
                                )
                                appendLine("child.styleClass += styleClass")
                                appendLine("child.id = id")
                                appendLine("child.configuration()")
                                appendLine {
                                    append("return ")
                                    if (managerClassName != null) append("addChild(")
                                    append("child")
                                    if (managerClassName != null) append(")")
                                }
                            }
                        }
                    }
                }
            }.writeTo(File(factory.path))
        }
        println("Finished!")
        println()
    }

    private fun FunSpecBuilder.contractln() =
        appendLine("%M { callsInPlace(configuration, %M) }", CONTRACT, EXACTLY_ONCE)

    private fun ParameterSpecHandlerScope.styleClass() = add("styleClass", String::class, VARARG) {
        kdoc.append("the CSS style class.")
    }

    private fun ParameterSpecHandlerScope.id() = add("id", String::class.asNullable()) {
        kdoc.append("the CSS id.")
        defaultValue("null")
    }

    private fun ParameterSpecHandlerScope.configuration(entry: LayoutsEntry) = add(
        "configuration", Unit::class.asClassName()
            .lambdaBy(receiver = entry.customTypeName.annotate(DSL_MARKER))
    ) {
        kdoc.append("the configuration block.")
    }
}

<|start_filename|>sample/src/com/example/CalculatorApp.kt<|end_filename|>
package com.example

import javafx.application.Application
import javafx.scene.control.Label
import javafx.stage.Stage
import ktfx.bindings.asBoolean
import ktfx.bindings.asString
import ktfx.controls.insetsOf
import ktfx.coroutines.onAction
import ktfx.dialogs.errorAlert
import ktfx.dialogs.infoAlert
import ktfx.launchApplication
import ktfx.layouts.button
import ktfx.layouts.gridPane
import ktfx.layouts.label
import ktfx.layouts.scene
import ktfx.layouts.vbox

class CalculatorApp : Application() {
    companion object {
        private val OPERATORS = arrayOf("+", "-", "/", "*")

        @JvmStatic
        fun main(vararg args: String) = launchApplication<CalculatorApp>(*args)
    }

    private lateinit var calculationLabel: Label
    private lateinit var resultLabel: Label

    override fun start(stage: Stage) {
        stage.scene {
            gridPane {
                vbox {
                    padding = insetsOf(horizontal = 20)
                    calculationLabel = label("")

                    resultLabel = label {
                        textProperty().bind(calculationLabel.textProperty().asString {
                            if (endsWithOperator(calculationLabel.text)) "..." else {
                                val operators = calculationLabel.text
                                    .split("\\d".toRegex())
                                    .filter { it.isNotEmpty() }
                                    .toMutableList()
                                val values = calculationLabel.text
                                    .split("[+\\-/*]".toRegex())
                                    .toMutableList()
                                var total: Double? = null
                                while (values.isNotEmpty() && operators.isNotEmpty()) {
                                    val value = values[0].toDouble()
                                    if (total != null) {
                                        total = when (operators[0]) {
                                            "+" -> total + value
                                            "-" -> total - value
                                            "/" -> total / value
                                            else -> total * value
                                        }
                                        operators.removeAt(0)
                                    } else {
                                        total = value
                                    }
                                    values.removeAt(0)
                                }
                                total?.toString() ?: "0"
                            }
                        })
                    }
                }.grid(0, 0 to 5).fillWidth()

                button("1") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("1") }
                }.grid(1, 0)
                button("2") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("2") }
                }.grid(1, 1)
                button("3") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("3") }
                }.grid(1, 2)

                button("4") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("4") }
                }.grid(2, 0)
                button("5") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("5") }
                }.grid(2, 1)
                button("6") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("6") }
                }.grid(2, 2)

                button("7") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("7") }
                }.grid(3, 0)
                button("8") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("8") }
                }.grid(3, 1)
                button("9") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("9") }
                }.grid(3, 2)

                button("0") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("0") }
                }.grid(4, 0)
                button("00") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("00") }
                }.grid(4, 1)
                button(".") {
                    setMinSize(40.0, 40.0)
                    onAction { errorAlert(":(", content = "Not yet supported.") }
                }.grid(4, 2)

                button("C") {
                    setMinSize(80.0, 40.0)
                    isCancelButton = true
                    onAction { calculationLabel.text = "" }
                }.grid(1, 3 to 2)
                button("*") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("*") }
                }.grid(2, 3)
                button("/") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("/") }
                }.grid(2, 4)
                button("+") {
                    setMinSize(40.0, 80.0)
                    onAction { appendText("+") }
                }.grid(3 to 2, 3)
                button("-") {
                    setMinSize(40.0, 40.0)
                    onAction { appendText("-") }
                }.grid(3, 4)
                button("=") {
                    setMinSize(40.0, 40.0)
                    isDefaultButton = true
                    disableProperty().bind(calculationLabel.textProperty().asBoolean(::endsWithOperator))
                    onAction { infoAlert("Result", content = resultLabel.text) }
                }.grid(4, 4)
            }
        }
        stage.isResizable = false
        stage.show()
    }

    private fun appendText(text: String) {
        if (text in OPERATORS && endsWithOperator(text)) {
            calculationLabel.text = calculationLabel.text.substring(0, calculationLabel.text.length)
        }
        calculationLabel.text += text
    }

    private fun endsWithOperator(text: String?): Boolean = OPERATORS.any { text!!.endsWith(it) }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/collections/ObservableCollectionsMapTest.kt<|end_filename|>
package ktfx.collections

import javafx.collections.ObservableMap
import com.hendraanggrian.ktfx.test.BaseMapTest

class ObservableCollectionsMapTest : BaseMapTest<ObservableMap<String, Any?>>() {

    override fun empty() = emptyObservableMap<String, Any?>()
    override fun of() = observableMapOf<String, Any?>()
    override fun of(value: String) = observableMapOf<String, Any?>(value to null)
    override fun of(vararg values: String) = observableMapOf<String, Any?>(*values.map { it to null }.toTypedArray())
    override fun mutableOf() = mutableObservableMapOf<String, Any?>()
    override fun mutableOf(vararg values: String) =
        mutableObservableMapOf<String, Any?>(*values.map { it to null }.toTypedArray())

    override fun Map<String, Any?>.to() = toObservableMap()
    override fun Map<String, Any?>.toMutable() = toMutableObservableMap()
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/text/TextFlowTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.paint.Color
import javafx.scene.text.TextFlow
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.Test
import kotlin.test.assertEquals

class TextFlowTest : LayoutsTest<KtfxPane, TextFlow>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = textFlow { }
    override fun KtfxPane.child2() = textFlow()
    override fun KtfxPane.child3() = textFlow { }

    @Test
    fun stringInvocation() {
        textFlow {
            "World" {
                fill = Color.RED
                assertEquals(fill, Color.RED)
            }
            assertEquals(children.size, 1)
        }
    }
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/ListViewTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.control.ListView
import javafx.scene.control.ScrollToEvent
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseListViewTest

class ListViewTest : BaseListViewTest() {

    override fun <E> ListView<E>.callOnEditStart(action: (ListView.EditEvent<E>) -> Unit) =
        onEditStart(Dispatchers.Unconfined) { action(it) }

    override fun <E> ListView<E>.callOnEditCommit(action: (ListView.EditEvent<E>) -> Unit) =
        onEditCommit(Dispatchers.Unconfined) { action(it) }

    override fun <E> ListView<E>.callOnEditCancel(action: (ListView.EditEvent<E>) -> Unit) =
        onEditCancel(Dispatchers.Unconfined) { action(it) }

    override fun <E> ListView<E>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit) =
        onScrollTo(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/web/WebEngineTest.kt<|end_filename|>
package ktfx.listeners

import javafx.geometry.Rectangle2D
import javafx.scene.web.BaseWebEngineTest
import javafx.scene.web.WebEngine
import javafx.scene.web.WebErrorEvent
import javafx.scene.web.WebEvent
import kotlin.test.Ignore

@Ignore
class WebEngineTest : BaseWebEngineTest() {

    override fun WebEngine.callOnAlert(action: (WebEvent<String>) -> Unit) = onAlert(action)
    override fun WebEngine.callOnStatusChanged(action: (WebEvent<String>) -> Unit) = onStatusChanged(action)
    override fun WebEngine.callOnResized(action: (WebEvent<Rectangle2D>) -> Unit) = onResized(action)
    override fun WebEngine.callOnVisibilityChanged(action: (WebEvent<Boolean>) -> Unit) = onVisibilityChanged(action)
    override fun WebEngine.callOnError(action: (WebErrorEvent) -> Unit) = onError(action)
}

<|start_filename|>ktfx-commons/tests/src/ktfx/ServiceTest.kt<|end_filename|>
package ktfx

import com.hendraanggrian.ktfx.test.initToolkit
import java.lang.Thread.sleep
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
import kotlin.test.fail

class ServiceTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun nullTest() = testService<Any> {
        setOnSucceeded {
            assertNull(value)
        }
    }

    @Test
    fun simple() = testService<Int> {
        call { 17 }
        setOnSucceeded {
            assertEquals(17, value)
            assertNotEquals(71, value)
        }
    }

    @Test
    fun expectFailure() = testService<String> {
        call { error("Sad face") }
        setOnFailed {
            assertTrue(it.source.exception is IllegalStateException)
        }
        setOnSucceeded {
            fail("Should not succeed.")
        }
    }

    private fun <V> testService(listener: (TaskBuilder<V>).() -> Unit) {
        buildService(listener).start()
        sleep(1000)
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/MoveToTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.MoveTo
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class MoveToTest : LayoutsTest<KtfxPath, MoveTo>() {

    override fun manager() = KtfxPath()
    override fun KtfxPath.childCount() = elements.size
    override fun child1() = moveTo { }
    override fun KtfxPath.child2() = moveTo()
    override fun KtfxPath.child3() = moveTo { }

    override fun MoveTo.testDefaultValues() {
        assertEquals(0.0, x)
        assertEquals(0.0, y)
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_HyperlinkLabel.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.HyperlinkLabel
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [HyperlinkLabel] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.hyperlinkLabel(text: String? = null): HyperlinkLabel = hyperlinkLabel(
    text =
    text
) { }

/**
 * Create a [HyperlinkLabel] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun hyperlinkLabel(
    text: String? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        HyperlinkLabel
    ).() -> Unit
): HyperlinkLabel {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = HyperlinkLabel(text)
    child.configuration()
    return child
}

/**
 * Add a [HyperlinkLabel] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.hyperlinkLabel(
    text: String? = null,
    configuration: (@KtfxLayoutDslMarker HyperlinkLabel).() -> Unit
): HyperlinkLabel {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = HyperlinkLabel(text)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [HyperlinkLabel].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledHyperlinkLabel(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null
): HyperlinkLabel = styledHyperlinkLabel(text = text, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [HyperlinkLabel] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledHyperlinkLabel(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null
): HyperlinkLabel = styledHyperlinkLabel(text = text, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [HyperlinkLabel] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledHyperlinkLabel(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker HyperlinkLabel).() -> Unit
): HyperlinkLabel {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = HyperlinkLabel(text)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [HyperlinkLabel] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledHyperlinkLabel(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker HyperlinkLabel).() -> Unit
): HyperlinkLabel {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = HyperlinkLabel(text)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXBadge.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXBadge
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXBadge] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.jfxBadge(): JFXBadge = jfxBadge() { }

/**
 * Create a [JFXBadge] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun jfxBadge(configuration: (@KtfxLayoutDslMarker KtfxJFXBadge).() -> Unit):
    JFXBadge {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXBadge()
    child.configuration()
    return child
}

/**
 * Add a [JFXBadge] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.jfxBadge(
    configuration: (@KtfxLayoutDslMarker KtfxJFXBadge).() ->
    Unit
): JFXBadge {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXBadge()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXBadge].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledJFXBadge(vararg styleClass: String, id: String? = null): JFXBadge =
    styledJFXBadge(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXBadge] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledJFXBadge(vararg styleClass: String, id: String? = null): JFXBadge =
    styledJFXBadge(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [JFXBadge] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledJFXBadge(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxJFXBadge).() -> Unit
): JFXBadge {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXBadge()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXBadge] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledJFXBadge(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxJFXBadge).() -> Unit
): JFXBadge {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXBadge()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/src/javafx/scene/control/KtfxButtonBar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.Button
import javafx.scene.control.ButtonBar
import kotlin.contracts.ExperimentalContracts

/**
 * [ButtonBar] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxButtonBar(buttonOrder: String?) : ButtonBar(buttonOrder), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { buttons += it }

    /** Call [NodeManager.button] by string invocation. */
    inline operator fun String.invoke(
        graphic: Node? = null,
        configuration: (@KtfxLayoutDslMarker Button).() -> Unit
    ): Button = button(this, graphic, configuration)
}


<|start_filename|>ktfx-commons/src/ktfx/inputs/Clipboard.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.inputs

import javafx.scene.input.Clipboard
import javafx.scene.input.DataFormat

/** Convenient method to put single content to clipboard. */
inline operator fun Clipboard.set(dataFormat: DataFormat, content: Any): Boolean =
    setContent(mapOf(dataFormat to content))

/** The content associated with this type, or null if there is none. */
inline operator fun Clipboard.get(dataFormat: DataFormat): Any? = getContent(dataFormat)

/** Returns true if there is content on this clipboard for this type. */
inline operator fun Clipboard.contains(dataFormat: DataFormat): Boolean = hasContent(dataFormat)


<|start_filename|>ktfx-commons/src/ktfx/controls/Backgrounds.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controls

import javafx.geometry.Insets
import javafx.scene.image.Image
import javafx.scene.layout.Background
import javafx.scene.layout.BackgroundFill
import javafx.scene.layout.BackgroundImage
import javafx.scene.layout.BackgroundPosition
import javafx.scene.layout.BackgroundRepeat
import javafx.scene.layout.BackgroundSize
import javafx.scene.layout.CornerRadii
import javafx.scene.layout.Region
import javafx.scene.paint.Paint
import ktfx.internal.KtfxInternals.NO_GETTER
import ktfx.internal.KtfxInternals.noGetter
import kotlin.DeprecationLevel.ERROR

/**
 * Builds new background with multiple [BackgroundFill] and/or [BackgroundImage].
 * @param builderAction populate newly created fill and/or image.
 * @return created background.
 */
inline fun buildBackground(
    builderAction: BackgroundBuilder.() -> Unit
): Background = BackgroundBuilder().apply(builderAction).build()

/**
 * Sets new background with multiple [BackgroundFill] and/or [BackgroundImage].
 * @param builderAction populate newly created fill and/or image.
 * @return applied background.
 */
inline fun Region.background(
    noinline builderAction: BackgroundBuilder.() -> Unit
): Background = buildBackground(builderAction).also { background = it }

/**
 * Sets new background with single [BackgroundFill].
 * @param builderAction fill configurator.
 * @return applied background.
 */
inline fun Region.backgroundFill(
    noinline builderAction: BackgroundBuilder.FillBuilder.() -> Unit
): Background = background { fill(builderAction) }

/**
 * Sets new background with single [BackgroundImage].
 * @param builderAction image configurator.
 * @return applied background.
 */
inline fun Region.backgroundImage(
    image: Image,
    noinline builderAction: BackgroundBuilder.ImageBuilder.() -> Unit
): Background = background { image(image, builderAction) }

/** Background configurator class. */
class BackgroundBuilder {

    /** Current fills within this background. */
    val fills: MutableList<BackgroundFill> = mutableListOf()

    /** Current images within this background. */
    val images: MutableList<BackgroundImage> = mutableListOf()

    /**
     * Append a [BackgroundFill].
     * @param builderAction fill configurator.
     * @return added fill.
     */
    inline fun fill(builderAction: FillBuilder.() -> Unit): BackgroundFill =
        FillBuilder().apply(builderAction).build().also { fills += it }

    /**
     * Append a [BackgroundImage].
     * @param builderAction image configurator.
     * @return added image.
     */
    inline fun image(image: Image, builderAction: ImageBuilder.() -> Unit): BackgroundImage =
        ImageBuilder(image).apply(builderAction).build().also { images += it }

    /** Return background based on current configuration. */
    fun build(): Background = Background(fills, images)

    /** Background fill configurator class. */
    class FillBuilder {
        /** Any Paint. If null, the value [javafx.scene.paint.Color.TRANSPARENT] is used.. */
        var fill: Paint? = null

        /** The corner Radii. If null, the value Radii.EMPTY is used. */
        var radii: CornerRadii? = null

        /** The insets. If null, the value Insets.EMPTY is used. */
        var insets: Insets? = null

        /** Return background fill based on current configuration. */
        fun build(): BackgroundFill = BackgroundFill(fill, radii, insets)
    }

    /** Background image configurator class. */
    class ImageBuilder(private val image: Image) {
        /** The repeat for the x axis. If null, this value defaults to [BackgroundRepeat.REPEAT]. */
        var repeatX: BackgroundRepeat? = null

        /** The repeat for the y axis. If null, this value defaults to [BackgroundRepeat.REPEAT]. */
        var repeatY: BackgroundRepeat? = null

        /** The repeat for the x and y axis. If null, this value defaults to [BackgroundRepeat.REPEAT]. */
        var repeat: BackgroundRepeat?
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                repeatX = value
                repeatY = value
            }

        /** The position to use. If null, defaults to [BackgroundPosition.DEFAULT]. */
        var position: BackgroundPosition? = null

        /** The size. If null, defaults to [BackgroundSize.DEFAULT]. */
        var size: BackgroundSize? = null

        /** Return background image based on current configuration. */
        fun build(): BackgroundImage = BackgroundImage(image, repeatX, repeatY, position, size)
    }
}


<|start_filename|>ktfx-commons/src/ktfx/collections/ObservableArraysInt.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ObservableArraysKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.collections

import javafx.collections.FXCollections
import javafx.collections.ObservableIntegerArray

/**
 * Creates a new empty observable [Int] array.
 * @see emptyArray
 */
inline fun emptyObservableIntArray(): ObservableIntegerArray = FXCollections.observableIntegerArray()

/**
 * Creates a new empty observable [Int] array.
 * @see intArrayOf
 */
inline fun observableIntArrayOf(): ObservableIntegerArray = FXCollections.observableIntegerArray()

/**
 * Returns an observable array containing the specified [Int] numbers.
 * @see intArrayOf
 */
fun observableIntArrayOf(vararg elements: Int): ObservableIntegerArray = when {
    elements.isNotEmpty() -> FXCollections.observableIntegerArray(*elements)
    else -> FXCollections.observableIntegerArray()
}

/**
 * Returns an observable array containing all of the [Int] numbers of this primitive array.
 * @see IntArray.toTypedArray
 */
inline fun IntArray.toObservableArray(): ObservableIntegerArray = FXCollections.observableIntegerArray(*this)

/** Returns an array containing copy of the observable array. */
fun ObservableIntegerArray.toFloatArray(): IntArray = toArray(IntArray(size()))

/**
 * Returns new observable array which is a copy of the original array.
 *
 * @see IntArray.copyOf
 */
inline fun ObservableIntegerArray.copyOf(): ObservableIntegerArray = FXCollections.observableIntegerArray(this)

/**
 * Returns `true` if [element] is found in the array.
 *
 * @see IntArray.contains
 */
operator fun ObservableIntegerArray.contains(element: Int): Boolean = indexOf(element) >= 0

/**
 * Returns first index of [element], or -1 if the array does not contain element.
 *
 * @see IntArray.indexOf
 */
fun ObservableIntegerArray.indexOf(element: Int): Int {
    for (index in indices) {
        if (element == this[index]) {
            return index
        }
    }
    return -1
}

/**
 * Returns last index of [element], or -1 if the array does not contain element.
 *
 * @see IntArray.lastIndexOf
 */
fun ObservableIntegerArray.lastIndexOf(element: Int): Int {
    for (index in indices.reversed()) {
        if (element == this[index]) {
            return index
        }
    }
    return -1
}

/**
 * Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
 *
 * @see IntArray.getOrElse
 */
inline fun ObservableIntegerArray.getOrElse(index: Int, defaultValue: (Int) -> Int): Int =
    if (index in 0..lastIndex) get(index) else defaultValue(index)

/**
 * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
 *
 * @see IntArray.getOrNull
 */
fun ObservableIntegerArray.getOrNull(index: Int): Int? =
    if (index in 0..lastIndex) get(index) else null

/** Adds the specified [element] to this observable array. */
inline operator fun ObservableIntegerArray.plusAssign(element: Int): Unit = addAll(element)

/** Adds all elements of the given [elements] array to this observable array. */
inline operator fun ObservableIntegerArray.plusAssign(elements: IntArray): Unit = addAll(*elements)

/** Adds all elements of the given [elements] observable array to this observable array. */
inline operator fun ObservableIntegerArray.plusAssign(elements: ObservableIntegerArray): Unit = addAll(elements)

/**
 * Performs the given [action] on each element.
 *
 * @see IntArray.forEach
 */
inline fun ObservableIntegerArray.forEach(action: (Int) -> Unit) {
    for (index in 0 until size()) {
        action(this[index])
    }
}

/**
 * Performs the given [action] on each element, providing sequential index with the element.
 *
 * @see IntArray.forEachIndexed
 */
inline fun ObservableIntegerArray.forEachIndexed(action: (index: Int, Int) -> Unit) {
    for (index in 0 until size()) {
        action(index, this[index])
    }
}

/**
 * Creates an iterator over the elements of the array.
 *
 * @see IntArray.iterator
 */
operator fun ObservableIntegerArray.iterator(): IntIterator = object : IntIterator() {
    var index = 0
    override fun hasNext() = index < size()
    override fun nextInt() = get(index++)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/CustomMenuItemTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.CustomMenuItem
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull
import kotlin.test.assertTrue

class CustomMenuItemTest : LayoutsTest<KtfxMenu, CustomMenuItem>() {

    override fun manager() = KtfxMenu("", null)
    override fun KtfxMenu.childCount() = items.size
    override fun child1() = customMenuItem { }
    override fun KtfxMenu.child2() = customMenuItem()
    override fun KtfxMenu.child3() = customMenuItem { }

    override fun CustomMenuItem.testDefaultValues() {
        assertNull(content)
        assertTrue(isHideOnClick)
    }
}

<|start_filename|>thirdparty/jfoenix-listeners/src/ktfx/jfoenix/listeners/_JFXDecorator.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.jfoenix.listeners

import com.jfoenix.controls.JFXDecorator
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see JFXDecorator.setOnCloseButtonAction
 */
public inline fun JFXDecorator.onCloseButtonAction(noinline action: () -> Unit) {
    return setOnCloseButtonAction(action)
}


<|start_filename|>ktfx-commons/src/ktfx/bindings/ArraysBindingFloat.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ArraysBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.FloatBinding
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableNumberValue
import javafx.collections.ObservableFloatArray

/** Creates a new [FloatBinding] that contains the element of an [ObservableFloatArray] at the specified position. */
inline fun ObservableFloatArray.getBinding(index: Int): FloatBinding =
    Bindings.floatValueAt(this, index)

/** Creates a new [FloatBinding] that contains the element of an [ObservableFloatArray] at the specified position. */
inline fun ObservableFloatArray.getBinding(index: ObservableNumberValue): FloatBinding =
    Bindings.floatValueAt(this, index)

/** Creates a new [FloatBinding] that contains the element of an [ObservableFloatArray] at the specified position. */
inline fun ObservableFloatArray.getBinding(index: ObservableIntegerValue): FloatBinding =
    Bindings.floatValueAt(this, index)

/**
 * Performs the given [action] on each element binding.
 * @see forEach
 */
inline fun ObservableFloatArray.forEachBinding(action: (FloatBinding) -> Unit) {
    for (index in 0 until size()) {
        action(Bindings.floatValueAt(this, index))
    }
}

/**
 * Performs the given [action] on each element binding, accompanied with the index of the element.
 * @see forEachIndexed
 */
inline fun ObservableFloatArray.forEachBindingIndexed(action: (index: Int, FloatBinding) -> Unit) {
    for (index in 0 until size()) {
        action(index, Bindings.floatValueAt(this, index))
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/MeshViewTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.MeshView
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class MeshViewTest : LayoutsTest<KtfxPane, MeshView>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = meshView { }
    override fun KtfxPane.child2() = meshView()
    override fun KtfxPane.child3() = meshView { }

    override fun MeshView.testDefaultValues() {
        assertNull(mesh)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/DatePickerTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.DatePicker
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class DatePickerTest : LayoutsTest<KtfxPane, DatePicker>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = datePicker { }
    override fun KtfxPane.child2() = datePicker()
    override fun KtfxPane.child3() = datePicker { }

    override fun DatePicker.testDefaultValues() {
        assertNull(value)
    }
}

<|start_filename|>ktfx-listeners/src/javafx/concurrent/Service.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.concurrent.Service
import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType

/** Registers an event filter to this task. */
inline fun <E : Event> Service<*>.eventFilter(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventFilter(type, it) }

/** Registers an event filter to this task. */
inline fun <E : Event> Service<*>.eventHandler(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventHandler(type, it) }


<|start_filename|>ktfx-commons/src/ktfx/bindings/NumberValueBindingLong.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("NumberValueBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.DoubleBinding
import javafx.beans.binding.FloatBinding
import javafx.beans.binding.LongBinding
import javafx.beans.binding.LongExpression
import javafx.beans.value.ObservableLongValue

/** @see LongExpression.negate */
inline operator fun ObservableLongValue.unaryMinus(): LongBinding = Bindings.negate(this) as LongBinding

/** @see LongExpression.add */
inline operator fun ObservableLongValue.plus(other: Double): DoubleBinding = Bindings.add(this, other)

/** @see LongExpression.add */
inline operator fun Double.plus(other: ObservableLongValue): DoubleBinding = Bindings.add(this, other)

/** @see LongExpression.add */
inline operator fun ObservableLongValue.plus(other: Float): FloatBinding = Bindings.add(this, other) as FloatBinding

/** @see LongExpression.add */
inline operator fun Float.plus(other: ObservableLongValue): FloatBinding = Bindings.add(this, other) as FloatBinding

/** @see LongExpression.add */
inline operator fun ObservableLongValue.plus(other: Long): LongBinding = Bindings.add(this, other) as LongBinding

/** @see LongExpression.add */
inline operator fun Long.plus(other: ObservableLongValue): LongBinding = Bindings.add(this, other) as LongBinding

/** @see LongExpression.add */
inline operator fun ObservableLongValue.plus(other: Int): LongBinding = Bindings.add(this, other) as LongBinding

/** @see LongExpression.add */
inline operator fun Int.plus(other: ObservableLongValue): LongBinding = Bindings.add(this, other) as LongBinding

/** @see LongExpression.subtract */
inline operator fun ObservableLongValue.minus(other: Double): DoubleBinding = Bindings.subtract(this, other)

/** @see LongExpression.subtract */
inline operator fun Double.minus(other: ObservableLongValue): DoubleBinding = Bindings.subtract(this, other)

/** @see LongExpression.subtract */
inline operator fun ObservableLongValue.minus(other: Float): FloatBinding =
    Bindings.subtract(this, other) as FloatBinding

/** @see LongExpression.subtract */
inline operator fun Float.minus(other: ObservableLongValue): FloatBinding =
    Bindings.subtract(this, other) as FloatBinding

/** @see LongExpression.subtract */
inline operator fun ObservableLongValue.minus(other: Long): LongBinding = Bindings.subtract(this, other) as LongBinding

/** @see LongExpression.subtract */
inline operator fun Long.minus(other: ObservableLongValue): LongBinding = Bindings.subtract(this, other) as LongBinding

/** @see LongExpression.subtract */
inline operator fun ObservableLongValue.minus(other: Int): LongBinding = Bindings.subtract(this, other) as LongBinding

/** @see LongExpression.subtract */
inline operator fun Int.minus(other: ObservableLongValue): LongBinding = Bindings.subtract(this, other) as LongBinding

/** @see LongExpression.multiply */
inline operator fun ObservableLongValue.times(other: Double): DoubleBinding = Bindings.multiply(this, other)

/** @see LongExpression.multiply */
inline operator fun Double.times(other: ObservableLongValue): DoubleBinding = Bindings.multiply(this, other)

/** @see LongExpression.multiply */
inline operator fun ObservableLongValue.times(other: Float): FloatBinding =
    Bindings.multiply(this, other) as FloatBinding

/** @see LongExpression.multiply */
inline operator fun Float.times(other: ObservableLongValue): FloatBinding =
    Bindings.multiply(this, other) as FloatBinding

/** @see LongExpression.multiply */
inline operator fun ObservableLongValue.times(other: Long): LongBinding = Bindings.multiply(this, other) as LongBinding

/** @see LongExpression.multiply */
inline operator fun Long.times(other: ObservableLongValue): LongBinding = Bindings.multiply(this, other) as LongBinding

/** @see LongExpression.multiply */
inline operator fun ObservableLongValue.times(other: Int): LongBinding = Bindings.multiply(this, other) as LongBinding

/** @see LongExpression.multiply */
inline operator fun Int.times(other: ObservableLongValue): LongBinding = Bindings.multiply(this, other) as LongBinding

/** @see LongExpression.divide */
inline operator fun ObservableLongValue.div(other: Double): DoubleBinding = Bindings.divide(this, other)

/** @see LongExpression.divide */
inline operator fun Double.div(other: ObservableLongValue): DoubleBinding = Bindings.divide(this, other)

/** @see LongExpression.divide */
inline operator fun ObservableLongValue.div(other: Float): FloatBinding = Bindings.divide(this, other) as FloatBinding

/** @see LongExpression.divide */
inline operator fun Float.div(other: ObservableLongValue): FloatBinding = Bindings.divide(this, other) as FloatBinding

/** @see LongExpression.divide */
inline operator fun ObservableLongValue.div(other: Long): LongBinding = Bindings.divide(this, other) as LongBinding

/** @see LongExpression.divide */
inline operator fun Long.div(other: ObservableLongValue): LongBinding = Bindings.divide(this, other) as LongBinding

/** @see LongExpression.divide */
inline operator fun ObservableLongValue.div(other: Int): LongBinding = Bindings.divide(this, other) as LongBinding

/** @see LongExpression.divide */
inline operator fun Int.div(other: ObservableLongValue): LongBinding = Bindings.divide(this, other) as LongBinding


<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXToggleNode.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXToggleNode
import javafx.scene.Node
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import ktfx.layouts.ToggleButtonManager
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXToggleNode] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.jfxToggleNode(graphic: Node? = null): JFXToggleNode = jfxToggleNode(
    graphic =
    graphic
) { }

/**
 * Add a [JFXToggleNode] to this manager.
 *
 * @return the control added.
 */
public fun ToggleButtonManager.jfxToggleNode(graphic: Node? = null): JFXToggleNode =
    jfxToggleNode(graphic = graphic) { }

/**
 * Create a [JFXToggleNode] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun jfxToggleNode(
    graphic: Node? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        JFXToggleNode
    ).() -> Unit
): JFXToggleNode {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleNode(graphic)
    child.configuration()
    return child
}

/**
 * Add a [JFXToggleNode] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.jfxToggleNode(
    graphic: Node? = null,
    configuration: (@KtfxLayoutDslMarker JFXToggleNode).() -> Unit
): JFXToggleNode {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleNode(graphic)
    child.configuration()
    return addChild(child)
}

/**
 * Add a [JFXToggleNode] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun ToggleButtonManager.jfxToggleNode(
    graphic: Node? = null,
    configuration: (@KtfxLayoutDslMarker JFXToggleNode).() -> Unit
): JFXToggleNode {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleNode(graphic)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXToggleNode].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledJFXToggleNode(
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null
): JFXToggleNode = styledJFXToggleNode(graphic = graphic, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXToggleNode] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledJFXToggleNode(
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null
): JFXToggleNode = styledJFXToggleNode(graphic = graphic, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXToggleNode] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun ToggleButtonManager.styledJFXToggleNode(
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null
): JFXToggleNode = styledJFXToggleNode(graphic = graphic, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [JFXToggleNode] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledJFXToggleNode(
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXToggleNode).() -> Unit
): JFXToggleNode {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleNode(graphic)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXToggleNode] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledJFXToggleNode(
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXToggleNode).() -> Unit
): JFXToggleNode {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleNode(graphic)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}

/**
 * Add a styled [JFXToggleNode] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun ToggleButtonManager.styledJFXToggleNode(
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXToggleNode).() -> Unit
): JFXToggleNode {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleNode(graphic)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/TableViewTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.TableColumn
import javafx.scene.control.TableView
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseTableViewTest

class TableViewTest : BaseTableViewTest() {

    override fun <S> TableView<S>.callOnSort(action: (SortEvent<TableView<S>>) -> Unit) =
        onSort(Dispatchers.Unconfined) { action(it) }

    override fun <S> TableView<S>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit) =
        onScrollTo(Dispatchers.Unconfined) { action(it) }

    override fun <S> TableView<S>.callOnScrollToColumn(action: (ScrollToEvent<TableColumn<S, *>>) -> Unit) =
        onScrollToColumn(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseDialogTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.control.Dialog
import javafx.scene.control.DialogEvent
import javafx.stage.Stage
import org.testfx.framework.junit.ApplicationTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseDialogTest : ApplicationTest() {
    private lateinit var dialog: Dialog<String>

    abstract fun <E> Dialog<E>.callOnCloseRequest(action: (DialogEvent) -> Unit)
    abstract fun <E> Dialog<E>.callOnShowing(action: (DialogEvent) -> Unit)
    abstract fun <E> Dialog<E>.callOnShown(action: (DialogEvent) -> Unit)
    abstract fun <E> Dialog<E>.callOnHiding(action: (DialogEvent) -> Unit)
    abstract fun <E> Dialog<E>.callOnHidden(action: (DialogEvent) -> Unit)

    override fun start(stage: Stage) {
        stage.testScene<Dialog<*>>()
        dialog = Dialog()
    }

    @Test
    fun onCloseRequest() {
        dialog.callOnCloseRequest {
            assertEquals(dialog, it.source)
            assertEquals(DialogEvent.DIALOG_CLOSE_REQUEST, it.eventType)
        }
        dialog.onCloseRequest.handle(DialogEvent(dialog, DialogEvent.DIALOG_CLOSE_REQUEST))
    }

    @Test
    fun onShowing() {
        dialog.callOnShowing {
            assertEquals(dialog, it.source)
            assertEquals(DialogEvent.DIALOG_SHOWING, it.eventType)
        }
        dialog.onShowing.handle(DialogEvent(dialog, DialogEvent.DIALOG_SHOWING))
    }

    @Test
    fun onShown() {
        dialog.callOnShown {
            assertEquals(dialog, it.source)
            assertEquals(DialogEvent.DIALOG_SHOWN, it.eventType)
        }
        dialog.onShown.handle(DialogEvent(dialog, DialogEvent.DIALOG_SHOWN))
    }

    @Test
    fun onHiding() {
        dialog.callOnHiding {
            assertEquals(dialog, it.source)
            assertEquals(DialogEvent.DIALOG_HIDING, it.eventType)
        }
        dialog.onHiding.handle(DialogEvent(dialog, DialogEvent.DIALOG_HIDING))
    }

    @Test
    fun onHidden() {
        dialog.callOnHidden {
            assertEquals(dialog, it.source)
            assertEquals(DialogEvent.DIALOG_HIDDEN, it.eventType)
        }
        dialog.onHidden.handle(DialogEvent(dialog, DialogEvent.DIALOG_HIDDEN))
    }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/CollectionsBindingList.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("CollectionsBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Binding
import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.DoubleBinding
import javafx.beans.binding.FloatBinding
import javafx.beans.binding.IntegerBinding
import javafx.beans.binding.LongBinding
import javafx.beans.binding.ObjectBinding
import javafx.beans.binding.StringBinding
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableNumberValue
import javafx.collections.ObservableList

/** Generates a bidirectional binding between two instances of [ObservableList]. */
inline fun <E> ObservableList<E>.bindContentBidirectional(other: ObservableList<E>): Unit =
    Bindings.bindContentBidirectional(this, other)

/** Remove a bidirectional binding between two instances of [ObservableList]. */
inline fun <E> ObservableList<E>.unbindContentBidirectional(other: ObservableList<E>): Unit =
    Bindings.unbindContentBidirectional(this, other)

/** Generates a bidirectional binding between an [ObservableList] and a [List]. */
inline fun <E> List<E>.bindContent(other: ObservableList<E>): Unit = Bindings.bindContent(this, other)

/** Remove a bidirectional binding between an [ObservableList] and a [List]. */
inline fun <E> List<E>.unbindContent(other: ObservableList<E>): Unit = Bindings.unbindContent(this, other)

/** Creates a new [IntegerBinding] that contains the size [ObservableList]. */
inline fun <E> ObservableList<E>.size(): IntegerBinding = Bindings.size(this)

/** Creates a new [BooleanBinding] that holds `true` if a given [ObservableList] is empty. */
inline val <E> ObservableList<E>.isEmpty: BooleanBinding get() = Bindings.isEmpty(this)

/** Creates a new [BooleanBinding] that holds `true` if a given [ObservableList] is not empty. */
inline val <E> ObservableList<E>.isNotEmpty: BooleanBinding get() = Bindings.isNotEmpty(this)

/** Creates a new [ObjectBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun <E> ObservableList<E>.getBinding(index: Int): ObjectBinding<E> =
    Bindings.valueAt(this, index)

/** Creates a new [ObjectBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun <E> ObservableList<E>.getBinding(index: ObservableNumberValue): ObjectBinding<E> =
    Bindings.valueAt(this, index)

/** Creates a new [ObjectBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun <E> ObservableList<E>.getBinding(index: ObservableIntegerValue): ObjectBinding<E> =
    Bindings.valueAt(this, index)

/** Creates a new [BooleanBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Boolean>.getBinding(index: Int): BooleanBinding =
    Bindings.booleanValueAt(this, index)

/** Creates a new [BooleanBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Boolean>.getBinding(index: ObservableNumberValue): BooleanBinding =
    Bindings.booleanValueAt(this, index)

/** Creates a new [BooleanBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Boolean>.getBinding(index: ObservableIntegerValue): BooleanBinding =
    Bindings.booleanValueAt(this, index)

/** Creates a new [DoubleBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Double>.getBinding(index: Int): DoubleBinding =
    Bindings.doubleValueAt(this, index)

/** Creates a new [DoubleBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Double>.getBinding(index: ObservableNumberValue): DoubleBinding =
    Bindings.doubleValueAt(this, index)

/** Creates a new [DoubleBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Double>.getBinding(index: ObservableIntegerValue): DoubleBinding =
    Bindings.doubleValueAt(this, index)

/** Creates a new [FloatBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Float>.getBinding(index: Int): FloatBinding =
    Bindings.floatValueAt(this, index)

/** Creates a new [FloatBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Float>.getBinding(index: ObservableNumberValue): FloatBinding =
    Bindings.floatValueAt(this, index)

/** Creates a new [FloatBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Float>.getBinding(index: ObservableIntegerValue): FloatBinding =
    Bindings.floatValueAt(this, index)

/** Creates a new [IntegerBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Int>.getBinding(index: Int): IntegerBinding =
    Bindings.integerValueAt(this, index)

/** Creates a new [IntegerBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Int>.getBinding(index: ObservableNumberValue): IntegerBinding =
    Bindings.integerValueAt(this, index)

/** Creates a new [IntegerBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Int>.getBinding(index: ObservableIntegerValue): IntegerBinding =
    Bindings.integerValueAt(this, index)

/** Creates a new [LongBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Long>.getBinding(index: Int): LongBinding =
    Bindings.longValueAt(this, index)

/** Creates a new [LongBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Long>.getBinding(index: ObservableNumberValue): LongBinding =
    Bindings.longValueAt(this, index)

/** Creates a new [LongBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<Long>.getBinding(index: ObservableIntegerValue): LongBinding =
    Bindings.longValueAt(this, index)

/** Creates a new [StringBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<String>.getBinding(index: Int): StringBinding =
    Bindings.stringValueAt(this, index)

/** Creates a new [StringBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<String>.getBinding(index: ObservableNumberValue): StringBinding =
    Bindings.stringValueAt(this, index)

/** Creates a new [StringBinding] that contains the element of an [ObservableList] at the specified position. */
inline fun ObservableList<String>.getBinding(index: ObservableIntegerValue): StringBinding =
    Bindings.stringValueAt(this, index)

/**
 * Performs the given [action] on each element.
 * @see List.forEach
 */
inline fun <E> ObservableList<E>.forEachBinding(action: (Binding<E>) -> Unit) {
    for (index in 0 until size) {
        action(getBinding(index))
    }
}

/**
 * Performs the given [action] on each element, providing sequential index with the element.
 * @see List.forEachIndexed
 */
inline fun <E> ObservableList<E>.forEachBindingIndexed(action: (index: Int, Binding<E>) -> Unit) {
    for (index in 0 until size) {
        action(index, getBinding(index))
    }
}


<|start_filename|>thirdparty/controlsfx-coroutines/src/ktfx/controlsfx/coroutines/_PlusMinusSlider.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxCoroutinesKt")

package ktfx.controlsfx.coroutines

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import org.controlsfx.control.PlusMinusSlider
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see PlusMinusSlider.setOnValueChanged
 */
public fun PlusMinusSlider.onValueChanged(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(PlusMinusSlider.PlusMinusEvent) -> Unit
) {
    return setOnValueChanged { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>testing/listeners-coroutines/src/javafx/scene/media/BaseMediaPlayerTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.media.Media
import javafx.scene.media.MediaMarkerEvent
import javafx.scene.media.MediaPlayer
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertTrue

abstract class BaseMediaPlayerTest {
    private lateinit var player: MediaPlayer

    abstract fun MediaPlayer.callOnError(action: () -> Unit)
    abstract fun MediaPlayer.callOnMarker(action: (MediaMarkerEvent) -> Unit)
    abstract fun MediaPlayer.callOnEndOfMedia(action: () -> Unit)
    abstract fun MediaPlayer.callOnReady(action: () -> Unit)
    abstract fun MediaPlayer.callOnPlaying(action: () -> Unit)
    abstract fun MediaPlayer.callOnPaused(action: () -> Unit)
    abstract fun MediaPlayer.callOnStopped(action: () -> Unit)
    abstract fun MediaPlayer.callOnHalted(action: () -> Unit)
    abstract fun MediaPlayer.callOnRepeat(action: () -> Unit)
    abstract fun MediaPlayer.callOnStalled(action: () -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        player = MediaPlayer(Media(javaClass.classLoader.getResource("sample.flv")!!.toString()))
    }

    @Test
    fun onError() {
        var isCalled = false
        player.callOnError { assertTrue(isCalled) }
        isCalled = true
        player.onError.run()
    }

    @Test
    fun onMarker() {
        // TODO: create fake event
        // player.callOnMarker { assertFakeMediaMarkerEvent(it) }
        // player.onMarker.handle(fakeMediaMarkerEventOf())
    }

    @Test
    fun onEndOfMedia() {
        var isCalled = false
        player.callOnEndOfMedia { assertTrue(isCalled) }
        isCalled = true
        player.onEndOfMedia.run()
    }

    @Test
    fun onReady() {
        var isCalled = false
        player.callOnReady { assertTrue(isCalled) }
        isCalled = true
        player.onReady.run()
    }

    @Test
    fun onPlaying() {
        var isCalled = false
        player.callOnPlaying { assertTrue(isCalled) }
        isCalled = true
        player.onPlaying.run()
    }

    @Test
    fun onPaused() {
        var isCalled = false
        player.callOnPaused { assertTrue(isCalled) }
        isCalled = true
        player.onPaused.run()
    }

    @Test
    fun onStopped() {
        var isCalled = false
        player.callOnStopped { assertTrue(isCalled) }
        isCalled = true
        player.onStopped.run()
    }

    @Test
    fun onHalted() {
        var isCalled = false
        player.callOnHalted { assertTrue(isCalled) }
        isCalled = true
        player.onHalted.run()
    }

    @Test
    fun onRepeat() {
        var isCalled = false
        player.callOnRepeat { assertTrue(isCalled) }
        isCalled = true
        player.onRepeat.run()
    }

    @Test
    fun onStalled() {
        var isCalled = false
        player.callOnStalled { assertTrue(isCalled) }
        isCalled = true
        player.onStalled.run()
    }
}

<|start_filename|>thirdparty/jfoenix-listeners/tests/src/com/jfoenix/controls/JFXDecoratorTest.kt<|end_filename|>
package ktfx.jfoenix.listeners

import com.jfoenix.controls.JFXDecorator
import ktfx.jfoenix.test.BaseJFXDecoratorTest

class JFXDecoratorTest : BaseJFXDecoratorTest() {

    override fun JFXDecorator.callOnCloseButtonAction(action: () -> Unit) =
        onCloseButtonAction(action)
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/ChoiceBoxTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.ChoiceBox
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseChoiceBoxTest

class ChoiceBoxTest : BaseChoiceBoxTest() {

    override fun <E> ChoiceBox<E>.callOnAction(action: (ActionEvent) -> Unit) =
        onAction(Dispatchers.Unconfined) { action(it) }

    override fun <E> ChoiceBox<E>.callOnShowing(action: (Event) -> Unit) =
        onShowing(Dispatchers.Unconfined) { action(it) }

    override fun <E> ChoiceBox<E>.callOnShown(action: (Event) -> Unit) =
        onShown(Dispatchers.Unconfined) { action(it) }

    override fun <E> ChoiceBox<E>.callOnHiding(action: (Event) -> Unit) =
        onHiding(Dispatchers.Unconfined) { action(it) }

    override fun <E> ChoiceBox<E>.callOnHidden(action: (Event) -> Unit) =
        onHidden(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>thirdparty/jfoenix-coroutines/tests/src/com/jfoenix/controls/JFXDrawerTest.kt<|end_filename|>
package ktfx.jfoenix.coroutines

import com.jfoenix.controls.JFXDrawer
import com.jfoenix.controls.events.JFXDrawerEvent
import kotlinx.coroutines.Dispatchers
import ktfx.jfoenix.test.BaseJFXDrawerTest

class JFXDrawerTest : BaseJFXDrawerTest() {

    override fun JFXDrawer.callOnDrawerClosed(action: (JFXDrawerEvent) -> Unit) =
        onDrawerClosed(Dispatchers.Unconfined) { action(it) }

    override fun JFXDrawer.callOnDrawerClosing(action: (JFXDrawerEvent) -> Unit) =
        onDrawerClosing(Dispatchers.Unconfined) { action(it) }

    override fun JFXDrawer.callOnDrawerOpened(action: (JFXDrawerEvent) -> Unit) =
        onDrawerOpened(Dispatchers.Unconfined) { action(it) }

    override fun JFXDrawer.callOnDrawerOpening(action: (JFXDrawerEvent) -> Unit) =
        onDrawerOpening(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-commons/src/ktfx/Service.kt<|end_filename|>
package ktfx

import javafx.concurrent.Service
import javafx.concurrent.Task

/** Receiver in `ktfx.buildService`, invoke [call] to customize what this Task do in the background. */
class TaskBuilder<V> internal constructor() : Task<V>() {
    private var _call: () -> V? = { null }

    fun call(onCall: () -> V?) {
        _call = onCall
    }

    override fun call(): V? = _call()
}

/**
 * Returns a [Service] by invoking [Task] DSL.
 * By default, it will do nothing and returns null in the background, customize it by invoking `call`.
 */
fun <V> buildService(builderAction: TaskBuilder<V>.() -> Unit): Service<V> = object : Service<V>() {
    override fun createTask(): Task<V> = TaskBuilder<V>().apply(builderAction)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/QuadCurveTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.QuadCurve
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class QuadCurveTest : LayoutsTest<KtfxPane, QuadCurve>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = quadCurve { }
    override fun KtfxPane.child2() = quadCurve()
    override fun KtfxPane.child3() = quadCurve { }

    override fun QuadCurve.testDefaultValues() {
        assertEquals(0.0, startX)
        assertEquals(0.0, startY)
        assertEquals(0.0, controlX)
        assertEquals(0.0, controlY)
        assertEquals(0.0, endX)
        assertEquals(0.0, endY)
    }
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_Media.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.media.Media
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Media.setOnError
 */
public inline fun Media.onError(noinline action: () -> Unit) {
    return setOnError(action)
}


<|start_filename|>thirdparty/jfoenix-listeners/src/ktfx/jfoenix/listeners/_JFXAnimationTimer.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.jfoenix.listeners

import com.jfoenix.transitions.JFXAnimationTimer
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see JFXAnimationTimer.setOnFinished
 */
public inline fun JFXAnimationTimer.onFinished(noinline action: () -> Unit) {
    return setOnFinished(action)
}


<|start_filename|>ktfx-coroutines/src/javafx/scene/Scene.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxCoroutinesKt")

package ktfx.coroutines

import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.scene.Scene
import javafx.scene.SnapshotResult
import javafx.scene.image.WritableImage
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

/** Registers an event filter to this scene. */
fun <E : Event> Scene.eventFilter(
    context: CoroutineContext = Dispatchers.JavaFx,
    type: EventType<E>,
    action: suspend CoroutineScope.(E) -> Unit
): EventHandler<E> = EventHandler<E> { event -> GlobalScope.launch(context) { action(event) } }
    .also { addEventFilter(type, it) }

/** Registers an event handler to this scene. */
fun <E : Event> Scene.eventHandler(
    context: CoroutineContext = Dispatchers.JavaFx,
    type: EventType<E>,
    action: suspend CoroutineScope.(E) -> Unit
): EventHandler<E> = EventHandler<E> { event -> GlobalScope.launch(context) { action(event) } }
    .also { addEventHandler(type, it) }

/** Takes a snapshot of this scene at the next frame and calls the specified callback method when the image is ready. */
fun Scene.capture(
    context: CoroutineContext = Dispatchers.JavaFx,
    image: WritableImage? = null,
    callback: suspend CoroutineScope.(SnapshotResult) -> Unit
): Unit = snapshot({ param -> GlobalScope.launch(context) { callback(param) }; null }, image)


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXSliderTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXSlider
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class JFXSliderTest : LayoutsTest<KtfxPane, JFXSlider>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxSlider { }
    override fun KtfxPane.child2() = jfxSlider()
    override fun KtfxPane.child3() = jfxSlider { }

    override fun JFXSlider.testDefaultValues() {
        assertEquals(0.0, min)
        assertEquals(100.0, max)
        assertEquals(50.0, value)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/controls/Effects.kt<|end_filename|>
package ktfx.controls

import javafx.scene.Node
import javafx.scene.effect.Blend
import javafx.scene.effect.Bloom
import javafx.scene.effect.BoxBlur
import javafx.scene.effect.ColorAdjust
import javafx.scene.effect.ColorInput
import javafx.scene.effect.DisplacementMap
import javafx.scene.effect.DropShadow
import javafx.scene.effect.GaussianBlur
import javafx.scene.effect.Glow
import javafx.scene.effect.ImageInput
import javafx.scene.effect.InnerShadow
import javafx.scene.effect.Lighting
import javafx.scene.effect.MotionBlur
import javafx.scene.effect.PerspectiveTransform
import javafx.scene.effect.Reflection
import javafx.scene.effect.SepiaTone
import javafx.scene.effect.Shadow

/**
 * Sets [Blend] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.blendEffect(configuration: Blend.() -> Unit): Blend = Blend().also {
    it.configuration()
    effect = it
}

/**
 * Sets [Bloom] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.bloomEffect(configuration: Bloom.() -> Unit): Bloom = Bloom().also {
    it.configuration()
    effect = it
}

/**
 * Sets [BoxBlur] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.boxBlurEffect(configuration: BoxBlur.() -> Unit): BoxBlur = BoxBlur().also {
    it.configuration()
    effect = it
}

/**
 * Sets [ColorAdjust] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.colorAdjustEffect(configuration: ColorAdjust.() -> Unit): ColorAdjust = ColorAdjust().also {
    it.configuration()
    effect = it
}

/**
 * Sets [ColorInput] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.colorInputEffect(configuration: ColorInput.() -> Unit): ColorInput = ColorInput().also {
    it.configuration()
    effect = it
}

/**
 * Sets [DisplacementMap] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.displacementMapEffect(configuration: DisplacementMap.() -> Unit): DisplacementMap = DisplacementMap().also {
    it.configuration()
    effect = it
}

/**
 * Sets [DropShadow] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.dropShadowEffect(configuration: DropShadow.() -> Unit): DropShadow = DropShadow().also {
    it.configuration()
    effect = it
}

/**
 * Sets [GaussianBlur] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.gaussianBlurEffect(configuration: GaussianBlur.() -> Unit): GaussianBlur = GaussianBlur().also {
    it.configuration()
    effect = it
}

/**
 * Sets [Glow] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.glowEffect(configuration: Glow.() -> Unit): Glow = Glow().also {
    it.configuration()
    effect = it
}

/**
 * Sets [ImageInput] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.imageInputEffect(configuration: ImageInput.() -> Unit): ImageInput = ImageInput().also {
    it.configuration()
    effect = it
}

/**
 * Sets [InnerShadow] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.innerShadowEffect(configuration: InnerShadow.() -> Unit): InnerShadow = InnerShadow().also {
    it.configuration()
    effect = it
}

/**
 * Sets [Lighting] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.lightingEffect(configuration: Lighting.() -> Unit): Lighting = Lighting().also {
    it.configuration()
    effect = it
}

/**
 * Sets [MotionBlur] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.motionBlurEffect(configuration: MotionBlur.() -> Unit): MotionBlur = MotionBlur().also {
    it.configuration()
    effect = it
}

/**
 * Sets [PerspectiveTransform] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.perspectiveTransformEffect(configuration: PerspectiveTransform.() -> Unit): PerspectiveTransform =
    PerspectiveTransform().also {
        it.configuration()
        effect = it
    }

/**
 * Sets [Reflection] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.reflectionEffect(configuration: Reflection.() -> Unit): Reflection = Reflection().also {
    it.configuration()
    effect = it
}

/**
 * Sets [SepiaTone] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.sepiaToneEffect(configuration: SepiaTone.() -> Unit): SepiaTone = SepiaTone().also {
    it.configuration()
    effect = it
}

/**
 * Sets [Shadow] effect.
 * @param configuration the configuration block that customizes effect.
 * @return the effect applied.
 */
fun Node.shadowEffect(configuration: Shadow.() -> Unit): Shadow = Shadow().also {
    it.configuration()
    effect = it
}


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_TreeView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.TreeView
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Int
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see TreeView.setOnEditStart
 */
public fun <T> TreeView<T>.onEditStart(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(TreeView.EditEvent<T>) -> Unit
) {
    return setOnEditStart { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TreeView.setOnEditCommit
 */
public fun <T> TreeView<T>.onEditCommit(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(TreeView.EditEvent<T>) -> Unit
) {
    return setOnEditCommit { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TreeView.setOnEditCancel
 */
public fun <T> TreeView<T>.onEditCancel(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(TreeView.EditEvent<T>) -> Unit
) {
    return setOnEditCancel { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TreeView.setOnScrollTo
 */
public fun <T> TreeView<T>.onScrollTo(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ScrollToEvent<Int>) -> Unit
) {
    return setOnScrollTo { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-commons/tests/src/com/hendraanggrian/ktfx/test/BaseCollectionsTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import kotlin.test.assertFails

/** All observable collection tests must follow this convention. */
abstract class BaseCollectionsTest<T : MutableCollection<String>> {

    private companion object {
        const val SINGLETON_VALUE = "Lonely text"
        val FILL_VALUES = arrayOf("I'm", "a", "little", "piggy")
        const val ADD_VALUE = "Oink"

        val ARRAY = arrayOf(*FILL_VALUES)
        val LIST = listOf(*FILL_VALUES)
        val SEQUENCE = sequenceOf(*FILL_VALUES)
    }

    abstract fun empty(): T
    abstract fun of(): T
    abstract fun of(value: String): T
    abstract fun of(vararg values: String): T
    abstract fun mutableOf(): T
    abstract fun mutableOf(vararg values: String): T

    @Test
    fun creating() {
        val empty = empty()
        assertThat(empty).isEmpty()
        assertFails { empty += ADD_VALUE }

        val unfilled = of()
        assertThat(unfilled).isEmpty()
        assertFails { unfilled += ADD_VALUE }

        val singleton = of(SINGLETON_VALUE)
        assertThat(singleton).containsExactly(SINGLETON_VALUE)
        assertFails { singleton += ADD_VALUE }

        val filled = of(*FILL_VALUES)
        assertThat(filled).containsExactly(*FILL_VALUES)
        assertFails { filled += ADD_VALUE }

        val mutableUnfilled = mutableOf()
        mutableUnfilled += ADD_VALUE
        assertThat(mutableUnfilled).containsExactly(ADD_VALUE)

        val mutableFilled = mutableOf(*FILL_VALUES)
        mutableFilled += ADD_VALUE
        assertThat(mutableFilled).containsExactly(*FILL_VALUES, ADD_VALUE)
    }

    abstract fun Array<String>.to(): T
    abstract fun List<String>.to(): T
    abstract fun Sequence<String>.to(): T
    abstract fun Array<String>.toMutable(): T
    abstract fun List<String>.toMutable(): T
    abstract fun Sequence<String>.toMutable(): T

    @Test
    fun converting() {
        val fromArray = ARRAY.to()
        assertThat(fromArray).containsExactly(*FILL_VALUES)
        assertFails { fromArray += ADD_VALUE }

        val fromList = LIST.to()
        assertThat(fromList).containsExactly(*FILL_VALUES)
        assertFails { fromList += ADD_VALUE }

        val fromSequence = SEQUENCE.to()
        assertThat(fromSequence).containsExactly(*FILL_VALUES)
        assertFails { fromSequence += ADD_VALUE }

        val mutableFromArray = ARRAY.toMutable()
        mutableFromArray += ADD_VALUE
        assertThat(mutableFromArray).containsExactly(*FILL_VALUES, ADD_VALUE)

        val mutableFromList = LIST.toMutable()
        mutableFromList += ADD_VALUE
        assertThat(mutableFromList).containsExactly(*FILL_VALUES, ADD_VALUE)

        val mutableFromSequence = SEQUENCE.toMutable()
        mutableFromSequence += ADD_VALUE
        assertThat(mutableFromSequence).containsExactly(*FILL_VALUES, ADD_VALUE)
    }
}


<|start_filename|>ktfx-commons/src/ktfx/controls/Node.kt<|end_filename|>
package ktfx.controls

import javafx.scene.Node
import javafx.scene.SnapshotParameters
import javafx.scene.image.WritableImage

/** Alias of [Node.lookup] with non-null return and specified type. */
inline fun <reified T : Node> Node.find(selector: String): T = lookup(selector) as T

/** Take a snapshot of this [Node] returning image it wrote. */
inline fun Node.capture(
    image: WritableImage? = null,
    configuration: SnapshotParameters.() -> Unit = { }
): WritableImage = snapshot(SnapshotParameters().apply(configuration), image)


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/Generator.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen

import com.hendraanggrian.ktfx.codegen.layouts.ControlsFx
import com.hendraanggrian.ktfx.codegen.layouts.JFoenix
import com.hendraanggrian.ktfx.codegen.layouts.JavaFx
import com.hendraanggrian.ktfx.codegen.layouts.LayoutsFactory
import com.hendraanggrian.ktfx.codegen.layouts.LayoutsWriter
import com.hendraanggrian.ktfx.codegen.listeners.ControlsFx
import com.hendraanggrian.ktfx.codegen.listeners.CoroutinesFactory
import com.hendraanggrian.ktfx.codegen.listeners.JFoenix
import com.hendraanggrian.ktfx.codegen.listeners.JavaFx
import com.hendraanggrian.ktfx.codegen.listeners.ListenersFactory
import com.hendraanggrian.ktfx.codegen.listeners.ListenersWriter

object Generator {

    @JvmStatic
    fun main(args: Array<String>) {
        if (true) {
            LayoutsWriter.write(LayoutsFactory.JavaFx)
            LayoutsWriter.write(LayoutsFactory.ControlsFx)
            LayoutsWriter.write(LayoutsFactory.JFoenix)
        }
        if (true) {
            ListenersWriter.write(ListenersFactory.JavaFx)
            ListenersWriter.write(CoroutinesFactory.JavaFx)
            ListenersWriter.write(ListenersFactory.ControlsFx)
            ListenersWriter.write(CoroutinesFactory.ControlsFx)
            ListenersWriter.write(ListenersFactory.JFoenix)
            ListenersWriter.write(CoroutinesFactory.JFoenix)
        }
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ButtonTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.Button
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class ButtonTest : LayoutsTest<KtfxButtonBar, Button>() {

    override fun manager() = KtfxButtonBar(null)
    override fun KtfxButtonBar.childCount() = buttons.size
    override fun child1() = button { }
    override fun KtfxButtonBar.child2() = button()
    override fun KtfxButtonBar.child3() = button { }

    override fun Button.testDefaultValues() {
        assertNull(text)
        assertNull(graphic)
    }
}

<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/controls/TextFields.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.controls

import javafx.scene.control.TextField
import javafx.util.StringConverter
import org.controlsfx.control.textfield.AutoCompletionBinding
import org.controlsfx.control.textfield.TextFields

/** Create a new auto-completion binding between the given [TextField] using the given auto-complete suggestions. */
inline fun <T> TextField.bindAutoCompletion(vararg possibleSuggestions: T): AutoCompletionBinding<T> =
    TextFields.bindAutoCompletion(this, *possibleSuggestions)

/** Alias of [bindAutoCompletion] with collection input. */
inline fun <T> TextField.bindAutoCompletion(possibleSuggestions: Collection<T>): AutoCompletionBinding<T> =
    TextFields.bindAutoCompletion(this, possibleSuggestions)

/** Create a new auto-completion binding between the given [TextField] and the given suggestion provider. */
inline fun <T> TextField.bindAutoCompletion(
    noinline suggestionProvider: (AutoCompletionBinding.ISuggestionRequest) -> Collection<T>
): AutoCompletionBinding<T> = TextFields.bindAutoCompletion(this, suggestionProvider)

/** Create a new auto-completion binding between the given [TextField] and the given suggestion provider. */
inline fun <T> TextField.bindAutoCompletion(
    converter: StringConverter<T>,
    noinline suggestionProvider: (AutoCompletionBinding.ISuggestionRequest) -> Collection<T>
): AutoCompletionBinding<T> = TextFields.bindAutoCompletion(this, suggestionProvider, converter)


<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/web/WebEngineTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.geometry.Rectangle2D
import javafx.scene.web.BaseWebEngineTest
import javafx.scene.web.WebEngine
import javafx.scene.web.WebErrorEvent
import javafx.scene.web.WebEvent
import kotlinx.coroutines.Dispatchers
import kotlin.test.Ignore

@Ignore
class WebEngineTest : BaseWebEngineTest() {

    override fun WebEngine.callOnAlert(action: (WebEvent<String>) -> Unit) =
        onAlert(Dispatchers.Unconfined) { action(it) }

    override fun WebEngine.callOnStatusChanged(action: (WebEvent<String>) -> Unit) =
        onStatusChanged(Dispatchers.Unconfined) { action(it) }

    override fun WebEngine.callOnResized(action: (WebEvent<Rectangle2D>) -> Unit) =
        onResized(Dispatchers.Unconfined) { action(it) }

    override fun WebEngine.callOnVisibilityChanged(action: (WebEvent<Boolean>) -> Unit) =
        onVisibilityChanged(Dispatchers.Unconfined) { action(it) }

    override fun WebEngine.callOnError(action: (WebErrorEvent) -> Unit) =
        onError(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-commons/src/ktfx/text/StringConverter.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.text

import javafx.util.StringConverter

/**
 * Builds new string converter.
 * @param builderAction configure [StringConverterBuilder.toString] and [StringConverterBuilder.fromString]
 * @return configured string converter.
 * @see kotlin.text.buildString
 */
inline fun <T> buildStringConverter(builderAction: StringConverterBuilder<T>.() -> Unit): StringConverter<T> =
    StringConverterBuilder<T>().apply(builderAction).build()

/** Receiver for `buildStringConverter` block. */
class StringConverterBuilder<T> {
    private var _toString: (T?) -> String = { it?.toString() ?: "" }
    private var _fromString: (String) -> T? = { null }

    /** Convert the object to String. */
    fun toString(listener: (T?) -> String) {
        _toString = listener
    }

    /** Convert String back to object. */
    fun fromString(listener: (String) -> T?) {
        _fromString = listener
    }

    /** Create to native builder. */
    fun build(): StringConverter<T> = object : StringConverter<T>() {
        override fun toString(any: T?): String = _toString(any)
        override fun fromString(string: String): T? = _fromString(string)
    }
}

/** Converts the object provided into its string form. */
inline operator fun <T> StringConverter<T>.invoke(obj: T): String = toString(obj)

/** Converts the string provided into an object defined by the specific converter. */
inline operator fun <T> StringConverter<T>.get(s: String): T = fromString(s)


<|start_filename|>ktfx-coroutines/tests/src/javafx/stage/WindowTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.stage.BaseWindowTest
import javafx.stage.Window
import javafx.stage.WindowEvent
import kotlinx.coroutines.Dispatchers

class WindowTest : BaseWindowTest() {

    override fun Window.callOnCloseRequest(action: (WindowEvent) -> Unit) =
        onCloseRequest(Dispatchers.Unconfined) { action(it) }

    override fun Window.callOnShowing(action: (WindowEvent) -> Unit) =
        onShowing(Dispatchers.Unconfined) { action(it) }

    override fun Window.callOnShown(action: (WindowEvent) -> Unit) =
        onShown(Dispatchers.Unconfined) { action(it) }

    override fun Window.callOnHiding(action: (WindowEvent) -> Unit) =
        onHiding(Dispatchers.Unconfined) { action(it) }

    override fun Window.callOnHidden(action: (WindowEvent) -> Unit) =
        onHidden(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>codegen/tests/src/com/hendraanggrian/ktfx/codegen/ListenersTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen

import kotlin.test.Test

class ListenersTest {

    @Test
    fun test() {
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXTimePickerTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTimePicker
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class JFXTimePickerTest : LayoutsTest<KtfxPane, JFXTimePicker>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxTimePicker { }
    override fun KtfxPane.child2() = jfxTimePicker()
    override fun KtfxPane.child3() = jfxTimePicker { }

    override fun JFXTimePicker.testDefaultValues() {
        assertNull(value)
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/animation/BaseAnimationTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.animation.Animation
import javafx.animation.ScaleTransition
import javafx.event.ActionEvent
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseAnimationTest {

    abstract fun Animation.callOnFinished(action: (ActionEvent) -> Unit)

    @Test
    fun onFinished() {
        val scale = ScaleTransition()
        scale.callOnFinished {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
        }
        scale.onFinished.handle(ActionEvent(this, FakeEventTarget))
    }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/SceneTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.BaseSceneTest
import javafx.scene.Scene
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent

class SceneTest : BaseSceneTest() {

    override fun Scene.callOnMouseClicked(action: (MouseEvent) -> Unit) = onMouseClicked(action)
    override fun Scene.callOnMouseDragged(action: (MouseEvent) -> Unit) = onMouseDragged(action)
    override fun Scene.callOnMouseEntered(action: (MouseEvent) -> Unit) = onMouseEntered(action)
    override fun Scene.callOnMouseExited(action: (MouseEvent) -> Unit) = onMouseExited(action)
    override fun Scene.callOnMouseMoved(action: (MouseEvent) -> Unit) = onMouseMoved(action)
    override fun Scene.callOnMousePressed(action: (MouseEvent) -> Unit) = onMousePressed(action)
    override fun Scene.callOnMouseReleased(action: (MouseEvent) -> Unit) = onMouseReleased(action)
    override fun Scene.callOnDragDetected(action: (MouseEvent) -> Unit) = onDragDetected(action)
    override fun Scene.callOnMouseDragOver(action: (MouseDragEvent) -> Unit) = onMouseDragOver(action)
    override fun Scene.callOnMouseDragReleased(action: (MouseDragEvent) -> Unit) = onMouseDragReleased(action)
    override fun Scene.callOnMouseDragEntered(action: (MouseDragEvent) -> Unit) = onMouseDragEntered(action)
    override fun Scene.callOnMouseDragExited(action: (MouseDragEvent) -> Unit) = onMouseDragExited(action)
    override fun Scene.callOnScrollStarted(action: (ScrollEvent) -> Unit) = onScrollStarted(action)
    override fun Scene.callOnScroll(action: (ScrollEvent) -> Unit) = onScroll(action)
    override fun Scene.callOnScrollFinished(action: (ScrollEvent) -> Unit) = onScrollFinished(action)
    override fun Scene.callOnRotationStarted(action: (RotateEvent) -> Unit) = onRotationStarted(action)
    override fun Scene.callOnRotate(action: (RotateEvent) -> Unit) = onRotate(action)
    override fun Scene.callOnRotationFinished(action: (RotateEvent) -> Unit) = onRotationFinished(action)
    override fun Scene.callOnZoomStarted(action: (ZoomEvent) -> Unit) = onZoomStarted(action)
    override fun Scene.callOnZoom(action: (ZoomEvent) -> Unit) = onZoom(action)
    override fun Scene.callOnZoomFinished(action: (ZoomEvent) -> Unit) = onZoomFinished(action)
    override fun Scene.callOnSwipeUp(action: (SwipeEvent) -> Unit) = onSwipeUp(action)
    override fun Scene.callOnSwipeDown(action: (SwipeEvent) -> Unit) = onSwipeDown(action)
    override fun Scene.callOnSwipeRight(action: (SwipeEvent) -> Unit) = onSwipeRight(action)
    override fun Scene.callOnSwipeLeft(action: (SwipeEvent) -> Unit) = onSwipeLeft(action)
    override fun Scene.callOnTouchPressed(action: (TouchEvent) -> Unit) = onTouchPressed(action)
    override fun Scene.callOnTouchMoved(action: (TouchEvent) -> Unit) = onTouchMoved(action)
    override fun Scene.callOnTouchReleased(action: (TouchEvent) -> Unit) = onTouchReleased(action)
    override fun Scene.callOnTouchStationary(action: (TouchEvent) -> Unit) = onTouchStationary(action)
    override fun Scene.callOnDragEntered(action: (DragEvent) -> Unit) = onDragEntered(action)
    override fun Scene.callOnDragExited(action: (DragEvent) -> Unit) = onDragExited(action)
    override fun Scene.callOnDragOver(action: (DragEvent) -> Unit) = onDragOver(action)
    override fun Scene.callOnDragDropped(action: (DragEvent) -> Unit) = onDragDropped(action)
    override fun Scene.callOnDragDone(action: (DragEvent) -> Unit) = onDragDone(action)
    override fun Scene.callOnKeyPressed(action: (KeyEvent) -> Unit) = onKeyPressed(action)
    override fun Scene.callOnKeyReleased(action: (KeyEvent) -> Unit) = onKeyReleased(action)
    override fun Scene.callOnKeyTyped(action: (KeyEvent) -> Unit) = onKeyTyped(action)
    override fun Scene.callOnInputMethodTextChanged(action: (InputMethodEvent) -> Unit) =
        onInputMethodTextChanged(action)

    override fun Scene.callOnContextMenuRequested(action: (ContextMenuEvent) -> Unit) = onContextMenuRequested(action)
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ContextMenuTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.TableColumn
import javafx.util.Duration
import com.hendraanggrian.ktfx.test.initToolkit
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

class ContextMenuTest {

    @BeforeTest fun start() = initToolkit()

    @Test
    fun stringInvocation() {
        contextMenu {
            menuItem("Hello")
            "World" {
            }
            assertEquals(2, items.size)
        }
    }

    @Test
    fun control() {
        button {
            contextMenu()
            assertNotNull(contextMenu)
        }
        button {
            contextMenu { }
            assertNotNull(contextMenu)
        }
    }

    @Test
    fun tab() {
        tab {
            contextMenu()
            assertNotNull(contextMenu)
        }
        tab {
            contextMenu { }
            assertNotNull(contextMenu)
        }
    }

    @Test
    fun tableColumn() {
        val column1 = TableColumn<Duration, String>()
        column1.contextMenu()
        assertNotNull(column1.contextMenu)
        val column2 = TableColumn<Duration, String>()
        column2.contextMenu()
        assertNotNull(column2.contextMenu)
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/media/BaseMediaViewTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.media.MediaErrorEvent
import javafx.scene.media.MediaView
import kotlin.test.BeforeTest
import kotlin.test.Test

abstract class BaseMediaViewTest {
    private lateinit var media: MediaView

    abstract fun MediaView.callOnError(action: (MediaErrorEvent) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        media = MediaView()
    }

    @Test
    fun onError() {
        // TODO: create fake event
        // media.callOnError { assertFakeMediaErrorEvent(it) }
        // media.onError.handle(fakeMediaErrorEventOf())
    }
}

<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_Menu.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.event.Event
import javafx.scene.control.Menu
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Menu.setOnShowing
 */
public fun Menu.onShowing(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnShowing { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Menu.setOnShown
 */
public fun Menu.onShown(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnShown { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Menu.setOnHiding
 */
public fun Menu.onHiding(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnHiding { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Menu.setOnHidden
 */
public fun Menu.onHidden(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnHidden { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-commons/src/ktfx/text/Font.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FontKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.text

import javafx.scene.text.Font
import javafx.scene.text.FontPosture
import javafx.scene.text.FontWeight

/** Returns a default font with size of this [Int] number. */
val Int.pt: Font get() = Font.font(toDouble())

/** Returns a default font with size of this [Double] number. */
inline val Double.pt: Font get() = Font.font(this)

/** Composes a font from configuration using [Int] size. */
fun fontOf(
    family: String = "System",
    weight: FontWeight = FontWeight.NORMAL,
    posture: FontPosture = FontPosture.REGULAR,
    size: Int
): Font = Font.font(family, weight, posture, size.toDouble())

/** Composes a font from configuration using [Double] size. */
inline fun fontOf(
    family: String = "System",
    weight: FontWeight = FontWeight.NORMAL,
    posture: FontPosture = FontPosture.REGULAR,
    size: Double = Font.getDefault().size
): Font = Font.font(family, weight, posture, size)


<|start_filename|>ktfx-commons/src/ktfx/controls/Selections.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controls

import javafx.beans.binding.BooleanBinding
import javafx.scene.control.MultipleSelectionModel
import javafx.scene.control.SelectionModel
import ktfx.bindings.isEmpty
import ktfx.bindings.isNotEmpty

/** Returns `true` if the model is selected. */
inline fun SelectionModel<*>.isSelected(): Boolean = selectedItem != null

/** Returns `true` if the model is not selected. */
inline fun SelectionModel<*>.isNotSelected(): Boolean = selectedItem == null

/** Returns `true` if the model is selected. */
inline fun MultipleSelectionModel<*>.isSelected(): Boolean = selectedItems.isNotEmpty()

/** Returns `true` if the model is not selected. */
inline fun MultipleSelectionModel<*>.isNotSelected(): Boolean = selectedItems.isEmpty()

/** Returns a boolean binding that holds `true` when item is selected. */
inline val SelectionModel<*>.selectedBinding: BooleanBinding get() = selectedItemProperty().isNotNull

/** Returns a boolean binding that holds `true` when item is not selected. */
inline val SelectionModel<*>.notSelectedBinding: BooleanBinding get() = selectedItemProperty().isNull

/** Returns a boolean binding that holds `true` when item is selected. */
inline val MultipleSelectionModel<*>.selectedBinding: BooleanBinding get() = selectedItems.isNotEmpty

/** Returns a boolean binding that holds `true` when item is not selected. */
inline val MultipleSelectionModel<*>.notSelectedBinding: BooleanBinding get() = selectedItems.isEmpty


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/listeners/ListenersEntries.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.listeners

import com.hendraanggrian.kotlinpoet.FileSpecBuilder
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.ParameterSpec
import com.squareup.kotlinpoet.ParameterizedTypeName
import com.squareup.kotlinpoet.TypeName

data class ListenersClassEntry(
    val receiver: TypeName,
    val extraFunctionModifier: KModifier?,
    val functions: MutableList<ListenersFunctionEntry>,
    val extraFileConfiguration: FileSpecBuilder.() -> Unit
) {

    val generatedName: String
        get() = when (receiver) {
            is ParameterizedTypeName -> receiver.rawType
            else -> receiver
        }.toString().substringAfterLast('.')

    val kdocType: TypeName
        get() = when (receiver) {
            is ParameterizedTypeName -> receiver.rawType
            else -> receiver
        }
}

data class ListenersFunctionEntry(
    val functionName: String,
    val parameters: List<ParameterSpec>
) {

    val simpleFunctionName: String
        get() = when {
            functionName.startsWith("set") -> {
                val s = functionName.substringAfter("set")
                s.first().lowercaseChar() + s.drop(1)
            }
            else -> functionName
        }
}

<|start_filename|>ktfx-commons/src/ktfx/controls/ToggleGroup.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controls

import javafx.beans.binding.BooleanBinding
import javafx.scene.control.ToggleGroup

/** Returns `true` if toggle button is selected in this group. */
inline fun ToggleGroup.isSelected(): Boolean = selectedToggle != null

/** Returns `true` if toggle button is not selected in this group. */
inline fun ToggleGroup.isNotSelected(): Boolean = selectedToggle == null

/** Returns a boolean binding that holds `true` when item is selected. */
inline val ToggleGroup.selectedBinding: BooleanBinding get() = selectedToggleProperty().isNotNull

/** Returns a boolean binding that holds `true` when item is not selected. */
inline val ToggleGroup.notSelectedBinding: BooleanBinding get() = selectedToggleProperty().isNull

/** Get selected toggle index. */
inline val ToggleGroup.selectedIndex: Int get() = toggles.indexOf(selectedToggle)

/** Select toggle by index. */
inline fun ToggleGroup.selectIndex(index: Int): Unit = selectToggle(toggles[index])


<|start_filename|>thirdparty/controlsfx-coroutines/tests/src/org/controlsfx/control/BreadCrumbBarTest.kt<|end_filename|>
package ktfx.controlsfx.coroutines

import kotlinx.coroutines.Dispatchers
import ktfx.controlsfx.test.BaseBreadCrumbBarTest
import org.controlsfx.control.BreadCrumbBar

class BreadCrumbBarTest : BaseBreadCrumbBarTest() {

    override fun <E> BreadCrumbBar<E>.callOnCrumbAction(action: (BreadCrumbBar.BreadCrumbActionEvent<E>) -> Unit) =
        onCrumbAction(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXToolbarTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.google.common.truth.Truth.assertThat
import com.jfoenix.controls.JFXButton
import com.jfoenix.controls.JFXToolbar
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.Test

class JFXToolbarTest : LayoutsTest<KtfxPane, JFXToolbar>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxToolbar { }
    override fun KtfxPane.child2() = jfxToolbar()
    override fun KtfxPane.child3() = jfxToolbar { }

    @Test
    fun leftAndRightItems() {
        val left1: JFXButton
        val right1: JFXButton
        val right2: JFXButton
        jfxToolbar {
            leftItems {
                left1 = jfxButton()
            }
            rightItems {
                right1 = jfxButton()
                right2 = jfxButton()
            }
            assertThat(leftItems).containsExactly(left1).inOrder()
            assertThat(rightItems).containsExactly(right1, right2).inOrder()
        }
    }
}

<|start_filename|>thirdparty/controlsfx-listeners/src/ktfx/controlsfx/listeners/_PlusMinusSlider.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.listeners

import org.controlsfx.control.PlusMinusSlider
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see PlusMinusSlider.setOnValueChanged
 */
public inline fun PlusMinusSlider.onValueChanged(
    noinline
    action: (PlusMinusSlider.PlusMinusEvent) -> Unit
) {
    return setOnValueChanged(action)
}


<|start_filename|>ktfx-layouts/src/javafx/scene/text/KtfxTextFlow.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.text.Text
import javafx.scene.text.TextFlow
import kotlin.contracts.ExperimentalContracts

/**
 * [TextFlow] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxTextFlow : TextFlow(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { children += it }

    /** Call [NodeManager.text] by string invocation. */
    inline operator fun String.invoke(
        configuration: (@KtfxLayoutDslMarker Text).() -> Unit
    ): Text = text(this, configuration)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/CheckBoxTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.CheckBox
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class CheckBoxTest : LayoutsTest<KtfxPane, CheckBox>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = checkBox { }
    override fun KtfxPane.child2() = checkBox()
    override fun KtfxPane.child3() = checkBox { }

    override fun CheckBox.testDefaultValues() {
        assertNull(text)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ComboBoxTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.control.ComboBox
import com.hendraanggrian.ktfx.test.LayoutsTest

class ComboBoxTest : LayoutsTest<KtfxPane, ComboBox<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = comboBox<String> { }
    override fun KtfxPane.child2() = comboBox<String>()
    override fun KtfxPane.child3() = comboBox<String> { }

    override fun ComboBox<String>.testDefaultValues() {
        assertThat(items).isEmpty()
    }
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/ContextMenuTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.event.ActionEvent
import javafx.scene.control.ContextMenu
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseContextMenuTest

class ContextMenuTest : BaseContextMenuTest() {

    override fun ContextMenu.callOnAction(action: (ActionEvent) -> Unit) =
        onAction(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-coroutines/src/javafx/beans/Observable.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxCoroutinesKt")

package ktfx.coroutines

import javafx.beans.InvalidationListener
import javafx.beans.Observable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

/** Adds an [InvalidationListener] which will be notified whenever the [Observable] becomes invalid. */
fun Observable.listener(
    context: CoroutineContext = Dispatchers.JavaFx,
    listener: suspend CoroutineScope.(Observable) -> Unit
): InvalidationListener = InvalidationListener { observable ->
    GlobalScope.launch(context) { listener(observable) }
}.also { addListener(it) }


<|start_filename|>ktfx-listeners/src/javafx/scene/transform/Transform.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.scene.transform.Transform

/** Registers an event filter to this transform. */
inline fun <E : Event> Transform.eventFilter(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventFilter(type, it) }

/** Registers an event handler to this transform. */
inline fun <E : Event> Transform.eventHandler(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventHandler(type, it) }


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/HyperlinkLabelTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.HyperlinkLabel
import kotlin.test.assertNull

class HyperlinkLabelTest : LayoutsTest<KtfxPane, HyperlinkLabel>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = hyperlinkLabel { }
    override fun KtfxPane.child2() = hyperlinkLabel()
    override fun KtfxPane.child3() = hyperlinkLabel { }

    override fun HyperlinkLabel.testDefaultValues() {
        assertNull(text)
    }
}

<|start_filename|>thirdparty/controlsfx/build.gradle.kts<|end_filename|>
group = RELEASE_GROUP
version = RELEASE_VERSION

plugins {
    kotlin("jvm")
    `maven-publish`
    signing
}

dependencies {
    api(project(":thirdparty:controlsfx-commons"))
    api(project(":thirdparty:controlsfx-layouts"))
    api(project(":thirdparty:controlsfx-listeners"))
    api(project(":thirdparty:controlsfx-coroutines"))
}

mavenPublishJvm("controlsfx")

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Polygon.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.Polygon
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [Polygon] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.polygon(): Polygon = polygon() { }

/**
 * Create a [Polygon] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun polygon(configuration: (@KtfxLayoutDslMarker Polygon).() -> Unit): Polygon {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Polygon()
    child.configuration()
    return child
}

/**
 * Add a [Polygon] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.polygon(configuration: (@KtfxLayoutDslMarker Polygon).() -> Unit):
    Polygon {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Polygon()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Polygon].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledPolygon(vararg styleClass: String, id: String? = null): Polygon =
    styledPolygon(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [Polygon] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledPolygon(vararg styleClass: String, id: String? = null): Polygon =
    styledPolygon(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [Polygon] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledPolygon(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Polygon).() -> Unit
): Polygon {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Polygon()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Polygon] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledPolygon(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Polygon).() -> Unit
): Polygon {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Polygon()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/TextAreaTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.TextArea
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class TextAreaTest : LayoutsTest<KtfxPane, TextArea>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = textArea { }
    override fun KtfxPane.child2() = textArea()
    override fun KtfxPane.child3() = textArea { }

    override fun TextArea.testDefaultValues() {
        assertEquals("", text)
    }
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_TableView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.TableColumn
import javafx.scene.control.TableView

/**
 * @see TableView.setOnSort
 */
public inline fun <S> TableView<S>.onSort(noinline action: (SortEvent<TableView<S>>) -> Unit) {
    return setOnSort(action)
}

/**
 * @see TableView.setOnScrollTo
 */
public inline fun <S> TableView<S>.onScrollTo(noinline action: (ScrollToEvent<Int>) -> Unit) {
    return setOnScrollTo(action)
}

/**
 * @see TableView.setOnScrollToColumn
 */
public inline fun <S> TableView<S>.onScrollToColumn(
    noinline action: (ScrollToEvent<TableColumn<S, *>>) -> Unit
) {
    return setOnScrollToColumn(action)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/NumberValueBindingIntegerTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.intPropertyOf
import kotlin.test.Test
import kotlin.test.assertEquals

class NumberValueBindingIntegerTest {

    @Test
    fun unaryMinus() = assertEquals(-1, (-intPropertyOf(1)).value)

    @Test
    fun plus() {
        // observable int to double
        assertEquals(3.0, (intPropertyOf(1) + 2.0).value)
        assertEquals(3.0, (2.0 + intPropertyOf(1)).value)
        // observable int to float
        assertEquals(3f, (intPropertyOf(1) + 2f).value)
        assertEquals(3f, (2f + intPropertyOf(1)).value)
        // observable int to long
        assertEquals(3L, (intPropertyOf(1) + 2L).value)
        assertEquals(3L, (2L + intPropertyOf(1)).value)
        // observable int to int
        assertEquals(3, (intPropertyOf(1) + 2).value)
        assertEquals(3, (2 + intPropertyOf(1)).value)
    }

    @Test
    fun minus() {
        // observable int to double
        assertEquals(-1.0, (intPropertyOf(1) - 2.0).value)
        assertEquals(1.0, (2.0 - intPropertyOf(1)).value)
        // observable int to float
        assertEquals(-1f, (intPropertyOf(1) - 2f).value)
        assertEquals(1f, (2f - intPropertyOf(1)).value)
        // observable int to long
        assertEquals(-1L, (intPropertyOf(1) - 2L).value)
        assertEquals(1L, (2L - intPropertyOf(1)).value)
        // observable int to int
        assertEquals(-1, (intPropertyOf(1) - 2).value)
        assertEquals(1, (2 - intPropertyOf(1)).value)
    }

    @Test
    fun times() {
        // observable int to double
        assertEquals(2.0, (intPropertyOf(1) * 2.0).value)
        assertEquals(2.0, (2.0 * intPropertyOf(1)).value)
        // observable int to float
        assertEquals(2f, (intPropertyOf(1) * 2f).value)
        assertEquals(2f, (2f * intPropertyOf(1)).value)
        // observable int to long
        assertEquals(2L, (intPropertyOf(1) * 2L).value)
        assertEquals(2L, (2L * intPropertyOf(1)).value)
        // observable int to int
        assertEquals(2, (intPropertyOf(1) * 2).value)
        assertEquals(2, (2 * intPropertyOf(1)).value)
    }

    @Test
    fun div() {
        // observable int to double
        assertEquals(0.5, (intPropertyOf(1) / 2.0).value)
        assertEquals(2.0, (2.0 / intPropertyOf(1)).value)
        // observable int to float
        assertEquals(0.5f, (intPropertyOf(1) / 2f).value)
        assertEquals(2f, (2f / intPropertyOf(1)).value)
        // observable int to long
        assertEquals(0L, (intPropertyOf(1) / 2L).value)
        assertEquals(2L, (2L / intPropertyOf(1)).value)
        // observable int to int
        assertEquals(0, (intPropertyOf(1) / 2).value)
        assertEquals(2, (2 / intPropertyOf(1)).value)
    }
}


<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/dialogs/FontSelectorsTest.kt<|end_filename|>
package ktfx.controlsfx.dialogs

import javafx.scene.text.Font
import com.hendraanggrian.ktfx.test.DialogShowingTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class FontSelectorsTest : DialogShowingTest() {

    private val arial18 = Font.font("Arial", 18.0)

    @Test
    fun exceptionDialog() {
        interact {
            assertEquals(
                arial18,
                fontSelector("Font selector", sampleGraphic, arial18) {
                    closeOnShow(this)
                    assertEquals("Font selector", headerText)
                    assertEquals(sampleGraphic, graphic)
                }.get()
            )
            assertEquals(arial18, fontSelector(arial18) { closeOnShow(this) }.get())
        }
    }
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_Service.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.concurrent.Service
import javafx.concurrent.WorkerStateEvent
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Service.setOnReady
 */
public inline fun Service<*>.onReady(noinline action: (WorkerStateEvent) -> Unit) {
    return setOnReady(action)
}

/**
 * @see Service.setOnScheduled
 */
public inline fun Service<*>.onScheduled(noinline action: (WorkerStateEvent) -> Unit) {
    return setOnScheduled(action)
}

/**
 * @see Service.setOnRunning
 */
public inline fun Service<*>.onRunning(noinline action: (WorkerStateEvent) -> Unit) {
    return setOnRunning(action)
}

/**
 * @see Service.setOnSucceeded
 */
public inline fun Service<*>.onSucceeded(noinline action: (WorkerStateEvent) -> Unit) {
    return setOnSucceeded(action)
}

/**
 * @see Service.setOnCancelled
 */
public inline fun Service<*>.onCancelled(noinline action: (WorkerStateEvent) -> Unit) {
    return setOnCancelled(action)
}

/**
 * @see Service.setOnFailed
 */
public inline fun Service<*>.onFailed(noinline action: (WorkerStateEvent) -> Unit) {
    return setOnFailed(action)
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXScrollPaneTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.google.common.truth.Truth.assertThat
import com.jfoenix.controls.JFXButton
import com.jfoenix.controls.JFXScrollPane
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.Test

class JFXScrollPaneTest : LayoutsTest<KtfxPane, JFXScrollPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxScrollPane { }
    override fun KtfxPane.child2() = jfxScrollPane()
    override fun KtfxPane.child3() = jfxScrollPane { }

    @Test
    fun barAndHeader() {
        val top1: JFXButton
        val mid1: JFXButton
        val mid2: JFXButton
        val bottom1: JFXButton
        val bottom2: JFXButton
        val bottom3: JFXButton
        val main1: JFXButton
        val condensed1: JFXButton
        val condensed2: JFXButton
        jfxScrollPane {
            topBar {
                top1 = jfxButton()
            }
            midBar {
                mid1 = jfxButton()
                mid2 = jfxButton()
            }
            bottomBar {
                bottom1 = jfxButton()
                bottom2 = jfxButton()
                bottom3 = jfxButton()
            }
            mainHeader {
                main1 = jfxButton()
            }
            condensedHeader {
                condensed1 = jfxButton()
                condensed2 = jfxButton()
            }
            assertThat(topBar.children).containsExactly(top1).inOrder()
            assertThat(midBar.children).containsExactly(mid1, mid2).inOrder()
            assertThat(bottomBar.children).containsExactly(bottom1, bottom2, bottom3).inOrder()
            assertThat(mainHeader.children).containsExactly(main1).inOrder()
            assertThat(condensedHeader.children).containsExactly(condensed1, condensed2).inOrder()
        }
    }
}

<|start_filename|>testing/listeners-coroutines/src/com/hendraanggrian/ktfx/test/events/FakeDragEvent.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.EventType
import javafx.scene.input.DragEvent
import javafx.scene.input.TransferMode
import kotlin.test.assertEquals
import kotlin.test.assertNull

/**
 * @receiver source of this fake event.
 */
fun Any.assertFakeDragEvent(actual: DragEvent, expectedType: EventType<DragEvent>) {
    assertEquals(this, actual.source)
    assertEquals(FakeEventTarget, actual.target)
    assertEquals(expectedType, actual.eventType)
    assertNull(actual.dragboard)
    assertEquals(0.0, actual.x)
    assertEquals(0.0, actual.y)
    assertEquals(0.0, actual.sceneX)
    assertEquals(0.0, actual.sceneY)
    assertEquals(TransferMode.MOVE, actual.transferMode)
    assertNull(actual.gestureSource)
    assertNull(actual.gestureTarget)
    assertEquals(FakePickResult, actual.pickResult)
}

/**
 * @receiver source of this fake event.
 */
fun Any.fakeDragEventOf(eventType: EventType<DragEvent>) = DragEvent(
    this, FakeEventTarget, eventType, null,
    0.0, 0.0,
    0.0, 0.0, TransferMode.MOVE,
    null, null, FakePickResult
)

<|start_filename|>ktfx-commons/src/ktfx/bindings/ComparisonsBinding.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.DoubleBinding
import javafx.beans.binding.NumberBinding
import javafx.beans.value.ObservableNumberValue

/** @see kotlin.comparisons.maxOf */
inline fun maxOf(a: ObservableNumberValue, b: ObservableNumberValue): NumberBinding = Bindings.max(a, b)

/** @see kotlin.comparisons.maxOf */
inline fun maxOf(a: ObservableNumberValue, b: Double): DoubleBinding = Bindings.max(a, b)

/** @see kotlin.comparisons.maxOf */
inline fun maxOf(a: Double, b: ObservableNumberValue): DoubleBinding = Bindings.max(a, b)

/** @see kotlin.comparisons.maxOf */
inline fun maxOf(a: ObservableNumberValue, b: Float): NumberBinding = Bindings.max(a, b)

/** @see kotlin.comparisons.maxOf */
inline fun maxOf(a: Float, b: ObservableNumberValue): NumberBinding = Bindings.max(a, b)

/** @see kotlin.comparisons.maxOf */
inline fun maxOf(a: ObservableNumberValue, b: Long): NumberBinding = Bindings.max(a, b)

/** @see kotlin.comparisons.maxOf */
inline fun maxOf(a: Long, b: ObservableNumberValue): NumberBinding = Bindings.max(a, b)

/** @see kotlin.comparisons.maxOf */
inline fun maxOf(a: ObservableNumberValue, b: Int): NumberBinding = Bindings.max(a, b)

/** @see kotlin.comparisons.maxOf */
inline fun maxOf(a: Int, b: ObservableNumberValue): NumberBinding = Bindings.max(a, b)

/** @see kotlin.comparisons.minOf */
inline fun minOf(a: ObservableNumberValue, b: ObservableNumberValue): NumberBinding = Bindings.min(a, b)

/** @see kotlin.comparisons.minOf */
inline fun minOf(a: ObservableNumberValue, b: Double): DoubleBinding = Bindings.min(a, b)

/** @see kotlin.comparisons.minOf */
inline fun minOf(a: Double, b: ObservableNumberValue): DoubleBinding = Bindings.min(a, b)

/** @see kotlin.comparisons.minOf */
inline fun minOf(a: ObservableNumberValue, b: Float): NumberBinding = Bindings.min(a, b)

/** @see kotlin.comparisons.minOf */
inline fun minOf(a: Float, b: ObservableNumberValue): NumberBinding = Bindings.min(a, b)

/** @see kotlin.comparisons.minOf */
inline fun minOf(a: ObservableNumberValue, b: Long): NumberBinding = Bindings.min(a, b)

/** @see kotlin.comparisons.minOf */
inline fun minOf(a: Long, b: ObservableNumberValue): NumberBinding = Bindings.min(a, b)

/** @see kotlin.comparisons.minOf */
inline fun minOf(a: ObservableNumberValue, b: Int): NumberBinding = Bindings.min(a, b)

/** @see kotlin.comparisons.minOf */
inline fun minOf(a: Int, b: ObservableNumberValue): NumberBinding = Bindings.min(a, b)


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/TextFieldTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.TextField
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class TextFieldTest : LayoutsTest<KtfxPane, TextField>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = textField { }
    override fun KtfxPane.child2() = textField()
    override fun KtfxPane.child3() = textField { }

    override fun TextField.testDefaultValues() {
        assertEquals("", text)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/CollectionsBindingMap.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("CollectionsBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.DoubleBinding
import javafx.beans.binding.FloatBinding
import javafx.beans.binding.IntegerBinding
import javafx.beans.binding.LongBinding
import javafx.beans.binding.ObjectBinding
import javafx.beans.binding.StringBinding
import javafx.beans.value.ObservableValue
import javafx.collections.ObservableMap

/** Generates a bidirectional binding between two instances of [ObservableMap]. */
inline fun <K, V> ObservableMap<K, V>.bindContentBidirectional(other: ObservableMap<K, V>): Unit =
    Bindings.bindContentBidirectional(this, other)

/** Remove a bidirectional binding between two instances of [ObservableMap]. */
inline fun <K, V> ObservableMap<K, V>.unbindContentBidirectional(other: ObservableMap<K, V>): Unit =
    Bindings.unbindContentBidirectional(this, other)

/** Generates a bidirectional binding between an [ObservableMap] and a [Map]. */
inline fun <K, V> Map<K, V>.bindContent(other: ObservableMap<K, V>): Unit = Bindings.bindContent(this, other)

/** Remove a bidirectional binding between an [ObservableMap] and a [Map]. */
inline fun <K, V> Map<K, V>.unbindContent(other: ObservableMap<K, V>): Unit = Bindings.unbindContent(this, other)

/** Creates a new [IntegerBinding] that contains the size [ObservableMap]. */
inline fun <K, V> ObservableMap<K, V>.size(): IntegerBinding = Bindings.size(this)

/** Creates a new [BooleanBinding] that holds `true` if a given [ObservableMap] is empty. */
inline val <K, V> ObservableMap<K, V>.isEmpty: BooleanBinding get() = Bindings.isEmpty(this)

/** Creates a new [BooleanBinding] that holds `true` if a given [ObservableMap] is not empty. */
inline val <K, V> ObservableMap<K, V>.isNotEmpty: BooleanBinding get() = Bindings.isNotEmpty(this)

/** Creates a new [ObjectBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K, V> ObservableMap<K, V>.getBinding(key: K): ObjectBinding<V> =
    Bindings.valueAt(this, key)

/** Creates a new [ObjectBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K, V> ObservableMap<K, V>.getBinding(key: ObservableValue<K>): ObjectBinding<V> =
    Bindings.valueAt(this, key)

/** Creates a new [BooleanBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, Boolean>.getBinding(key: K): BooleanBinding =
    Bindings.booleanValueAt(this, key)

/** Creates a new [BooleanBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, Boolean>.getBinding(key: ObservableValue<K>): BooleanBinding =
    Bindings.booleanValueAt(this, key)

/** Creates a new [DoubleBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, Double>.getBinding(key: K): DoubleBinding =
    Bindings.doubleValueAt(this, key)

/** Creates a new [DoubleBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, Double>.getBinding(key: ObservableValue<K>): DoubleBinding =
    Bindings.doubleValueAt(this, key)

/** Creates a new [FloatBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, Float>.getBinding(key: K): FloatBinding =
    Bindings.floatValueAt(this, key)

/** Creates a new [FloatBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, Float>.getBinding(key: ObservableValue<K>): FloatBinding =
    Bindings.floatValueAt(this, key)

/** Creates a new [IntegerBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, Int>.getBinding(key: K): IntegerBinding =
    Bindings.integerValueAt(this, key)

/** Creates a new [IntegerBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, Int>.getBinding(key: ObservableValue<K>): IntegerBinding =
    Bindings.integerValueAt(this, key)

/** Creates a new [LongBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, Long>.getBinding(key: K): LongBinding =
    Bindings.longValueAt(this, key)

/** Creates a new [LongBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, Long>.getBinding(key: ObservableValue<K>): LongBinding =
    Bindings.longValueAt(this, key)

/** Creates a new [StringBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, String>.getBinding(key: K): StringBinding =
    Bindings.stringValueAt(this, key)

/** Creates a new [StringBinding] that contains the mapping of a specific key in an [ObservableMap]. */
inline fun <K> ObservableMap<K, String>.getBinding(key: ObservableValue<K>): StringBinding =
    Bindings.stringValueAt(this, key)


<|start_filename|>testing/core/build.gradle.kts<|end_filename|>
plugins {
    javafx
    kotlin("jvm")
}

javafx {
    modules("javafx.controls")
}

sourceSets {
    main {
        java.srcDir("src")
    }
}

dependencies {
    api(kotlin("stdlib", VERSION_KOTLIN))
    api(kotlin("test-junit", VERSION_KOTLIN))
    api(google("truth", "truth", VERSION_TRUTH))

    api(testFx("testfx-junit"))
    api(testFx("openjfx-monocle", VERSION_MONOCLE))
    api(junit())
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/TreeViewTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.TreeView
import com.hendraanggrian.ktfx.test.BaseTreeViewTest

class TreeViewTest : BaseTreeViewTest() {

    override fun <E> TreeView<E>.callOnEditStart(action: (TreeView.EditEvent<E>) -> Unit) = onEditStart(action)
    override fun <E> TreeView<E>.callOnEditCommit(action: (TreeView.EditEvent<E>) -> Unit) = onEditCommit(action)
    override fun <E> TreeView<E>.callOnEditCancel(action: (TreeView.EditEvent<E>) -> Unit) = onEditCancel(action)
    override fun <E> TreeView<E>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit) = onScrollTo(action)
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/BooleanValueBinding.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.BooleanExpression
import javafx.beans.value.ObservableBooleanValue

/**
 * Creates a [BooleanBinding] that calculates the conditional-AND
 * operation on the value of two instance of [ObservableBooleanValue].
 * @see BooleanExpression.and
 */
inline infix fun ObservableBooleanValue.and(other: ObservableBooleanValue): BooleanBinding = Bindings.and(this, other)

/**
 * Creates a [BooleanBinding] that calculates the conditional-OR
 * operation on the value of two instance of [ObservableBooleanValue].
 * @see BooleanExpression.or
 */
inline infix fun ObservableBooleanValue.or(other: ObservableBooleanValue): BooleanBinding = Bindings.or(this, other)

/**
 * Creates a [BooleanBinding] that calculates the conditional-OR
 * operation on the value of two instance of [ObservableBooleanValue].
 * @see BooleanExpression.not
 */
inline operator fun ObservableBooleanValue.not(): BooleanBinding = Bindings.not(this)

/**
 * Creates a new [BooleanBinding] that holds `true`
 * if the values of two instances of [ObservableBooleanValue] are equal.
 * @see BooleanExpression.isEqualTo
 */
inline infix fun ObservableBooleanValue.eq(other: ObservableBooleanValue): BooleanBinding = Bindings.equal(this, other)

/**
 * Creates a new [BooleanBinding] that holds `true`
 * if the values of two instances of [ObservableBooleanValue] are not equal.
 * @see BooleanExpression.isNotEqualTo
 */
inline infix fun ObservableBooleanValue.neq(other: ObservableBooleanValue): BooleanBinding =
    Bindings.notEqual(this, other)


<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseTreeTableColumnTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.control.TreeTableColumn
import javafx.scene.control.TreeTablePosition
import javafx.scene.control.TreeTableView
import javafx.util.Duration
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseTreeTableColumnTest {
    private lateinit var table: TreeTableView<Duration>
    private lateinit var column: TreeTableColumn<Duration, Long>
    private lateinit var position: TreeTablePosition<Duration, Long>

    abstract fun <S, T> TreeTableColumn<S, T>.callOnEditStart(action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit)
    abstract fun <S, T> TreeTableColumn<S, T>.callOnEditCommit(action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit)
    abstract fun <S, T> TreeTableColumn<S, T>.callOnEditCancel(action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        table = TreeTableView()
        table.columns += TreeTableColumn<Duration, Long>().also { column = it }
        position = TreeTablePosition(table, 0, column)
    }

    @Test
    fun onEditStart() {
        column.callOnEditStart {
            assertEquals(table, it.source)
            assertEquals(position, it.treeTablePosition)
            assertEquals(TreeTableColumn.editStartEvent<Duration, Long>(), it.eventType)
            assertEquals(0, it.newValue)
        }
        column.onEditStart.handle(
            TreeTableColumn.CellEditEvent(table, position, TreeTableColumn.editStartEvent(), 0)
        )
    }

    @Test
    fun onEditCommit() {
        column.callOnEditCommit {
            assertEquals(table, it.source)
            assertEquals(position, it.treeTablePosition)
            assertEquals(TreeTableColumn.editCommitEvent<Duration, Long>(), it.eventType)
            assertEquals(0, it.newValue)
        }
        column.onEditCommit.handle(
            TreeTableColumn.CellEditEvent(table, position, TreeTableColumn.editCommitEvent(), 0)
        )
    }

    @Test
    fun onEditCancel() {
        column.callOnEditCancel {
            assertEquals(table, it.source)
            assertEquals(position, it.treeTablePosition)
            assertEquals(TreeTableColumn.editCancelEvent<Duration, Long>(), it.eventType)
            assertEquals(0, it.newValue)
        }
        column.onEditCancel.handle(
            TreeTableColumn.CellEditEvent(table, position, TreeTableColumn.editCancelEvent(), 0)
        )
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/layout/StackPaneTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.layout.StackPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class StackPaneTest : LayoutsTest<KtfxPane, StackPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = stackPane { }
    override fun KtfxPane.child2() = stackPane()
    override fun KtfxPane.child3() = stackPane { }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/BindingsFloat.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("BindingsKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.Observable
import javafx.beans.binding.Bindings
import javafx.beans.binding.FloatBinding
import javafx.beans.value.ObservableBooleanValue
import javafx.beans.value.ObservableDoubleValue
import javafx.beans.value.ObservableFloatValue
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableLongValue
import javafx.beans.value.ObservableObjectValue
import javafx.collections.ObservableList
import javafx.collections.ObservableMap
import javafx.collections.ObservableSet
import ktfx.collections.observableListOf
import ktfx.collections.toObservableList
import java.util.concurrent.Callable

/** Create a [FloatBinding] with multiple [Observable] dependencies. */
inline fun floatBindingOf(vararg dependencies: Observable, noinline valueProvider: () -> Float): FloatBinding =
    Bindings.createFloatBinding(Callable(valueProvider), *dependencies)

/** Create a [FloatBinding] with multiple [Observable] dependencies using collection. */
fun floatBindingOf(dependencies: Collection<Observable>, valueProvider: () -> Float): FloatBinding =
    floatBindingOf(*dependencies.toTypedArray(), valueProvider = valueProvider)

/** Create an [FloatBinding] with single [ObservableList] dependency. */
fun <E> ObservableList<E>.asFloat(valueProvider: (List<E>) -> Float): FloatBinding =
    object : FloatBinding() {
        override fun dispose(): Unit = unbind(this@asFloat)
        override fun computeValue(): Float = valueProvider(this@asFloat)
        override fun getDependencies(): ObservableList<*> = this@asFloat

        init {
            bind(this@asFloat)
        }
    }

/** Create an [FloatBinding] with single [ObservableSet] dependency. */
fun <E> ObservableSet<E>.asFloat(valueProvider: (Set<E>) -> Float): FloatBinding =
    object : FloatBinding() {
        override fun dispose(): Unit = unbind(this@asFloat)
        override fun computeValue(): Float = valueProvider(this@asFloat)
        override fun getDependencies(): ObservableList<*> = this@asFloat.toObservableList()

        init {
            bind(this@asFloat)
        }
    }

/** Create an [FloatBinding] with single [ObservableMap] dependency. */
fun <K, V> ObservableMap<K, V>.asFloat(valueProvider: (Map<K, V>) -> Float): FloatBinding =
    object : FloatBinding() {
        override fun dispose(): Unit = unbind(this@asFloat)
        override fun computeValue(): Float = valueProvider(this@asFloat)
        override fun getDependencies(): ObservableList<*> = this@asFloat.keys.toObservableList()

        init {
            bind(this@asFloat)
        }
    }

/** Create a [FloatBinding] with single [ObservableObjectValue] dependency. */
fun <V> ObservableObjectValue<V>.asFloat(valueProvider: (V?) -> Float): FloatBinding =
    object : FloatBinding() {
        override fun dispose(): Unit = unbind(this@asFloat)
        override fun computeValue(): Float = valueProvider(this@asFloat.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asFloat)

        init {
            bind(this@asFloat)
        }
    }

/** Create a [FloatBinding] with single [ObservableBooleanValue] dependency. */
fun ObservableBooleanValue.asFloat(valueProvider: (Boolean) -> Float): FloatBinding =
    object : FloatBinding() {
        override fun dispose(): Unit = unbind(this@asFloat)
        override fun computeValue(): Float = valueProvider(this@asFloat.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asFloat)

        init {
            bind(this@asFloat)
        }
    }

/** Create a [FloatBinding] with single [ObservableDoubleValue] dependency. */
fun ObservableDoubleValue.asFloat(valueProvider: (Double) -> Float): FloatBinding =
    object : FloatBinding() {
        override fun dispose(): Unit = unbind(this@asFloat)
        override fun computeValue(): Float = valueProvider(this@asFloat.value as Double)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asFloat)

        init {
            bind(this@asFloat)
        }
    }

/** Create a [FloatBinding] with single [ObservableFloatValue] dependency. */
fun ObservableFloatValue.asFloat(valueProvider: (Float) -> Float): FloatBinding =
    object : FloatBinding() {
        override fun dispose(): Unit = unbind(this@asFloat)
        override fun computeValue(): Float = valueProvider(this@asFloat.value as Float)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asFloat)

        init {
            bind(this@asFloat)
        }
    }

/** Create a [FloatBinding] with single [ObservableIntegerValue] dependency. */
fun ObservableIntegerValue.asFloat(valueProvider: (Int) -> Float): FloatBinding =
    object : FloatBinding() {
        override fun dispose(): Unit = unbind(this@asFloat)
        override fun computeValue(): Float = valueProvider(this@asFloat.value as Int)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asFloat)

        init {
            bind(this@asFloat)
        }
    }

/** Create a [FloatBinding] with single [ObservableLongValue] dependency. */
fun ObservableLongValue.asFloat(valueProvider: (Long) -> Float): FloatBinding =
    object : FloatBinding() {
        override fun dispose(): Unit = unbind(this@asFloat)
        override fun computeValue(): Float = valueProvider(this@asFloat.value as Long)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asFloat)

        init {
            bind(this@asFloat)
        }
    }


<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/TabTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.event.Event
import javafx.scene.control.Tab
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseTabTest

class TabTest : BaseTabTest() {

    override fun Tab.callOnSelectionChanged(action: (Event) -> Unit) =
        onSelectionChanged(Dispatchers.Unconfined) { action(it) }

    override fun Tab.callOnClosed(action: (Event) -> Unit) =
        onClosed(Dispatchers.Unconfined) { action(it) }

    override fun Tab.callOnCloseRequest(action: (Event) -> Unit) =
        onCloseRequest(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ChoiceBoxTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.control.ChoiceBox
import com.hendraanggrian.ktfx.test.LayoutsTest

class ChoiceBoxTest : LayoutsTest<KtfxPane, ChoiceBox<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = choiceBox<String> { }
    override fun KtfxPane.child2() = choiceBox<String>()
    override fun KtfxPane.child3() = choiceBox<String> { }

    override fun ChoiceBox<String>.testDefaultValues() {
        assertThat(items).isEmpty()
    }
}

<|start_filename|>ktfx-layouts/src/javafx/scene/control/KtfxToolBar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.ToolBar
import kotlin.contracts.ExperimentalContracts

/**
 * [ToolBar] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxToolBar : ToolBar(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { items += it }
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXTreeViewPathTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTreeView
import com.jfoenix.controls.JFXTreeViewPath
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXTreeViewPathTest : LayoutsTest<KtfxPane, JFXTreeViewPath>() {
    private lateinit var jfxTreeView: JFXTreeView<String>

    override fun onCreate() {
        super.onCreate()
        jfxTreeView = JFXTreeView()
    }

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxTreeViewPath(jfxTreeView) { }
    override fun KtfxPane.child2() = jfxTreeViewPath(jfxTreeView)
    override fun KtfxPane.child3() = jfxTreeViewPath(jfxTreeView) { }
}

<|start_filename|>testing/core/src/com/hendraanggrian/ktfx/test/Scene.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.geometry.Insets
import javafx.scene.Scene
import javafx.scene.control.Label
import javafx.scene.layout.VBox
import javafx.scene.text.Font
import javafx.scene.text.FontWeight
import javafx.stage.Stage

fun Stage.testScene(subject: String): Scene {
    scene = Scene(VBox(
        10.0,
        Label("Currently testing"),
        Label(subject).apply { font = Font.font("System", FontWeight.BLACK, 24.0) }
    ).apply { padding = Insets(20.0) })
    show()
    return scene
}

inline fun <reified T> Stage.testScene() = testScene(T::class.java.simpleName)

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_NotificationPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.NotificationPane
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [NotificationPane] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.notificationPane(): NotificationPane = notificationPane() { }

/**
 * Create a [NotificationPane] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun notificationPane(
    configuration: (@KtfxLayoutDslMarker KtfxNotificationPane).() ->
    Unit
): NotificationPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxNotificationPane()
    child.configuration()
    return child
}

/**
 * Add a [NotificationPane] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.notificationPane(
    configuration: (
        @KtfxLayoutDslMarker
        KtfxNotificationPane
    ).() -> Unit
): NotificationPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxNotificationPane()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [NotificationPane].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledNotificationPane(vararg styleClass: String, id: String? = null): NotificationPane =
    styledNotificationPane(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [NotificationPane] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledNotificationPane(vararg styleClass: String, id: String? = null):
    NotificationPane = styledNotificationPane(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [NotificationPane] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledNotificationPane(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxNotificationPane).() -> Unit
): NotificationPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxNotificationPane()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [NotificationPane] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledNotificationPane(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxNotificationPane).() -> Unit
): NotificationPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxNotificationPane()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-listeners/tests/src/javafx/scene/media/MediaPlayerTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.media.MediaMarkerEvent
import javafx.scene.media.MediaPlayer
import com.hendraanggrian.ktfx.test.BaseMediaPlayerTest
import kotlin.test.Ignore

@Ignore
class MediaPlayerTest : BaseMediaPlayerTest() {

    override fun MediaPlayer.callOnError(action: () -> Unit) = onError(action)
    override fun MediaPlayer.callOnMarker(action: (MediaMarkerEvent) -> Unit) = onMarker(action)
    override fun MediaPlayer.callOnEndOfMedia(action: () -> Unit) = onEndOfMedia(action)
    override fun MediaPlayer.callOnReady(action: () -> Unit) = onReady(action)
    override fun MediaPlayer.callOnPlaying(action: () -> Unit) = onPlaying(action)
    override fun MediaPlayer.callOnPaused(action: () -> Unit) = onPaused(action)
    override fun MediaPlayer.callOnStopped(action: () -> Unit) = onStopped(action)
    override fun MediaPlayer.callOnHalted(action: () -> Unit) = onHalted(action)
    override fun MediaPlayer.callOnRepeat(action: () -> Unit) = onRepeat(action)
    override fun MediaPlayer.callOnStalled(action: () -> Unit) = onStalled(action)
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Label.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.Label
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [Label] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.label(text: String? = null, graphic: Node? = null): Label = label(
    text =
    text,
    graphic = graphic
) { }

/**
 * Create a [Label] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun label(
    text: String? = null,
    graphic: Node? = null,
    configuration: (@KtfxLayoutDslMarker Label).() -> Unit
): Label {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Label(text, graphic)
    child.configuration()
    return child
}

/**
 * Add a [Label] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.label(
    text: String? = null,
    graphic: Node? = null,
    configuration: (@KtfxLayoutDslMarker Label).() -> Unit
): Label {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Label(text, graphic)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Label].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledLabel(
    text: String? = null,
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null
): Label = styledLabel(text = text, graphic = graphic, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [Label] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledLabel(
    text: String? = null,
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null
): Label = styledLabel(text = text, graphic = graphic, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [Label] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledLabel(
    text: String? = null,
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Label).() -> Unit
): Label {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Label(text, graphic)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Label] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledLabel(
    text: String? = null,
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Label).() -> Unit
): Label {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Label(text, graphic)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-coroutines/src/javafx/scene/control/MenuItem.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxCoroutinesKt")

package ktfx.coroutines

import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.scene.control.MenuItem
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

/** Registers an event handler to this [MenuItem]. */
fun <E : Event> MenuItem.eventHandler(
    context: CoroutineContext = Dispatchers.JavaFx,
    type: EventType<E>,
    action: suspend CoroutineScope.(E) -> Unit
): EventHandler<E> = EventHandler<E> { event -> GlobalScope.launch(context) { action(event) } }
    .also { addEventHandler(type, it) }


<|start_filename|>testing/listeners-coroutines/src/javafx/collections/BaseObservableListTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.collections.FXCollections
import javafx.collections.ListChangeListener
import javafx.collections.ObservableList
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

abstract class BaseObservableListTest {

    abstract fun <E> ObservableList<E>.callListener(action: (ListChangeListener.Change<out E>) -> Unit)

    @Test
    fun listener() {
        val list = FXCollections.observableArrayList<String>()
        list.callListener<String> {
            it.next()
            assertEquals(0, it.from)
            assertEquals(1, it.to)
            assertTrue(it.wasAdded())
            assertEquals("Hello world", it.addedSubList.single())
        }
        list.add("Hello world")
    }
}

<|start_filename|>ktfx-listeners/src/javafx/collections/ObservableSet.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.collections.ObservableSet
import javafx.collections.SetChangeListener
import javafx.collections.SetChangeListener.Change

/** Add a listener to this observable map. */
inline fun <E> ObservableSet<E>.listener(
    noinline listener: (Change<out E>) -> Unit
): SetChangeListener<E> = SetChangeListener<E>(listener).also { addListener(it) }


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_PopupWindow.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.Event
import javafx.stage.PopupWindow
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see PopupWindow.setOnAutoHide
 */
public inline fun PopupWindow.onAutoHide(noinline action: (Event) -> Unit) {
    return setOnAutoHide(action)
}


<|start_filename|>ktfx-commons/src/ktfx/Platform.kt<|end_filename|>
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx

import javafx.application.ConditionalFeature
import javafx.application.Platform
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/** Returns true if the calling thread is the JavaFX thread. */
inline fun isFxThread(): Boolean = Platform.isFxApplicationThread()

/** Queries whether a specific conditional feature is supported by the platform. */
inline fun ConditionalFeature.isSupported(): Boolean = Platform.isSupported(this)

/**
 * Calls the specified function [block] in JavaFX thread.
 * @see kotlin.run
 */
inline fun runLater(crossinline block: () -> Unit) {
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
    Platform.runLater { block() }
}

/**
 * Calls the specified function [block] with `this` value as its receiver in JavaFX thread.
 * @see kotlin.run
 */
inline fun <T> T.runLater(crossinline block: T.() -> Unit) {
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
    Platform.runLater { block() }
}

/**
 * Calls the specified function [block] with the given [receiver] as its receiver in JavaFX thread.
 * @see kotlin.with
 */
inline fun <T> withLater(receiver: T, crossinline block: T.() -> Unit) {
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
    Platform.runLater { receiver.block() }
}

/**
 * Calls the specified function [block] with `this` value as its receiver and returns `this` value in JavaFX thread.
 * @see kotlin.apply
 */
inline fun <T> T.applyLater(crossinline block: T.() -> Unit): T {
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
    Platform.runLater { block() }
    return this
}

/**
 * Calls the specified function [block] with `this` value as its argument and returns `this` value in JavaFX thread.
 * @see kotlin.also
 */
inline fun <T> T.alsoLater(crossinline block: (T) -> Unit): T {
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
    Platform.runLater { block(this) }
    return this
}

/**
 * Calls the specified function [block] with `this` value as its argument in JavaFX thread.
 * @see kotlin.let
 */
inline fun <T> T.letLater(crossinline block: (T) -> Unit) {
    contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
    Platform.runLater { block(this) }
}

/**
 * Executes the given function [action] specified number of [times] in JavaFX thread.
 * @see kotlin.repeat
 */
inline fun repeatLater(times: Int, crossinline action: (Int) -> Unit) {
    contract { callsInPlace(action) }
    Platform.runLater { for (index in 0 until times) action(index) }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/chart/PieChartTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.chart.PieChart
import com.hendraanggrian.ktfx.test.LayoutsTest

class PieChartTest : LayoutsTest<KtfxPane, PieChart>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = pieChart { }
    override fun KtfxPane.child2() = pieChart()
    override fun KtfxPane.child3() = pieChart { }

    override fun PieChart.testDefaultValues() {
        assertThat(data).isEmpty()
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/SplitPaneTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.SplitPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class SplitPaneTest : LayoutsTest<KtfxPane, SplitPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = splitPane { }
    override fun KtfxPane.child2() = splitPane()
    override fun KtfxPane.child3() = splitPane { }
}

<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/text/GlyphFont.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("Glyphs")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.text

import org.controlsfx.glyphfont.Glyph
import org.controlsfx.glyphfont.GlyphFont
import org.controlsfx.glyphfont.GlyphFontRegistry

/** Creates an instance of [Glyph] using specified font character. */
inline infix fun GlyphFont.glyph(character: Char): Glyph = create(character)

/** Creates an instance of [Glyph] using glyph name. */
inline infix fun GlyphFont.glyph(glyphName: String): Glyph = create(glyphName)

/** Creates an instance of [Glyph] using a known Glyph enum value. */
inline infix fun GlyphFont.glyph(glyph: Enum<*>): Glyph = create(glyph)

/** Registers the specified font. */
inline fun GlyphFont.register(): Unit = GlyphFontRegistry.register(this)


<|start_filename|>thirdparty/jfoenix-coroutines/src/ktfx/jfoenix/coroutines/_JFXAutoCompletePopup.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixCoroutinesKt")

package ktfx.jfoenix.coroutines

import com.jfoenix.controls.JFXAutoCompletePopup
import com.jfoenix.controls.events.JFXAutoCompleteEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see JFXAutoCompletePopup.setSelectionHandler
 */
public fun <T> JFXAutoCompletePopup<T>.selectionHandler(
    context: CoroutineContext =
        Dispatchers.JavaFx,
    action: suspend CoroutineScope.(JFXAutoCompleteEvent<T>) -> Unit
) {
    return setSelectionHandler { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ToggleButtonTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.ToggleButton
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class ToggleButtonTest : LayoutsTest<KtfxPane, ToggleButton>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = toggleButton { }
    override fun KtfxPane.child2() = toggleButton()
    override fun KtfxPane.child3() = toggleButton { }

    override fun ToggleButton.testDefaultValues() {
        assertNull(text)
        assertNull(graphic)
    }
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_MenuItem.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.MenuItem
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see MenuItem.setOnAction
 */
public inline fun MenuItem.onAction(noinline action: (ActionEvent) -> Unit) {
    return setOnAction(action)
}

/**
 * @see MenuItem.setOnMenuValidation
 */
public inline fun MenuItem.onMenuValidation(noinline action: (Event) -> Unit) {
    return setOnMenuValidation(action)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/canvas/CanvasTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.canvas.Canvas
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class CanvasTest : LayoutsTest<KtfxPane, Canvas>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = canvas { }
    override fun KtfxPane.child2() = canvas()
    override fun KtfxPane.child3() = canvas { }

    override fun Canvas.testDefaultValues() {
        assertEquals(0.0, width)
        assertEquals(0.0, height)
    }
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/TableColumnTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.control.TableColumn
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseTableColumnTest

class TableColumnTest : BaseTableColumnTest() {

    override fun <S, T> TableColumn<S, T>.callOnEditStart(action: (TableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditStart(Dispatchers.Unconfined) { action(it) }

    override fun <S, T> TableColumn<S, T>.callOnEditCommit(action: (TableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditCommit(Dispatchers.Unconfined) { action(it) }

    override fun <S, T> TableColumn<S, T>.callOnEditCancel(action: (TableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditCancel(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/stage/BasePopupWindowTest.kt<|end_filename|>
package javafx.stage

import javafx.event.Event
import javafx.scene.control.ContextMenu
import com.hendraanggrian.ktfx.test.FakeEventTarget
import com.hendraanggrian.ktfx.test.initToolkit
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BasePopupWindowTest {
    private lateinit var window: PopupWindow

    abstract fun PopupWindow.callOnAutoHide(action: (Event) -> Unit)

    @BeforeTest fun start() {
        initToolkit()
        window = ContextMenu()
    }

    @Test
    fun onAutoHide() {
        window.callOnAutoHide {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        window.onAutoHide.handle(Event(this, FakeEventTarget, Event.ANY))
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/media/BaseMediaTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.media.Media
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertTrue

abstract class BaseMediaTest {
    private lateinit var media: Media

    abstract fun Media.callOnError(action: () -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        media = Media(javaClass.classLoader.getResource("sample.flv")!!.toString())
    }

    @Test
    fun onError() {
        var isCalled = false
        media.callOnError { assertTrue(isCalled) }
        isCalled = true
        media.onError.run()
    }
}

<|start_filename|>testing/core/src/com/hendraanggrian/ktfx/test/Toolkit.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import com.sun.javafx.application.PlatformImpl

fun initToolkit() = PlatformImpl.startup { }

<|start_filename|>ktfx-coroutines/tests/src/javafx/collections/ObservableSetTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.collections.ObservableSet
import javafx.collections.SetChangeListener
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseObservableSetTest

class ObservableSetTest : BaseObservableSetTest() {

    override fun <E> ObservableSet<E>.callListener(action: (SetChangeListener.Change<out E>) -> Unit) {
        listener<E>(Dispatchers.Unconfined) { action(it) }
    }
}

<|start_filename|>thirdparty/jfoenix-commons/src/ktfx/jfoenix/controls/JFXDepthManager.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.jfoenix.controls

import com.jfoenix.effects.JFXDepthManager
import javafx.scene.Node
import ktfx.internal.KtfxInternals.NO_GETTER
import ktfx.internal.KtfxInternals.noGetter
import kotlin.DeprecationLevel.ERROR

/** This method is used to add shadow effect to the [Node]. */
inline var Node.depth: Int
    @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
    set(value) = JFXDepthManager.setDepth(this, value)

/**
 * This method will generate a new container node that prevent
 * control transformation to be applied to the shadow effect.
 */
inline fun Node.wrapDepth(level: Int): Node = JFXDepthManager.createMaterialNode(this, level)

/** Display drop shadow to this [Node]. */
inline fun Node.popDepth(): Unit = JFXDepthManager.pop(this)


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_TreeTableColumn.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.control.TreeTableColumn
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see TreeTableColumn.setOnEditStart
 */
public inline fun <S, T> TreeTableColumn<S, T>.onEditStart(
    noinline
    action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditStart(action)
}

/**
 * @see TreeTableColumn.setOnEditCommit
 */
public inline fun <S, T> TreeTableColumn<S, T>.onEditCommit(
    noinline
    action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditCommit(action)
}

/**
 * @see TreeTableColumn.setOnEditCancel
 */
public inline fun <S, T> TreeTableColumn<S, T>.onEditCancel(
    noinline
    action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditCancel(action)
}


<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/dialogs/ExceptionDialogsTest.kt<|end_filename|>
package ktfx.controlsfx.dialogs

import javafx.scene.control.ButtonType
import com.hendraanggrian.ktfx.test.DialogShowingTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class ExceptionDialogsTest : DialogShowingTest() {

    @Test
    fun exceptionDialog() {
        interact {
            assertEquals(
                ButtonType.OK,
                exceptionDialog("Exception dialog", sampleGraphic, UnsupportedOperationException()) {
                    closeOnShow(this)
                    assertEquals("Exception dialog", headerText)
                    assertEquals(sampleGraphic, graphic)
                }.get()
            )
            assertEquals(ButtonType.OK, exceptionDialog(UnsupportedOperationException()) {
                closeOnShow(this)
            }.get())
        }
    }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_AnchorPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.layout.AnchorPane
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add an [AnchorPane] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.anchorPane(): AnchorPane = anchorPane() { }

/**
 * Create an [AnchorPane] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun anchorPane(configuration: (@KtfxLayoutDslMarker KtfxAnchorPane).() -> Unit):
    AnchorPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxAnchorPane()
    child.configuration()
    return child
}

/**
 * Add an [AnchorPane] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.anchorPane(
    configuration: (@KtfxLayoutDslMarker KtfxAnchorPane).() ->
    Unit
): AnchorPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxAnchorPane()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [AnchorPane].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledAnchorPane(vararg styleClass: String, id: String? = null): AnchorPane =
    styledAnchorPane(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [AnchorPane] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledAnchorPane(vararg styleClass: String, id: String? = null): AnchorPane =
    styledAnchorPane(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [AnchorPane] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledAnchorPane(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxAnchorPane).() -> Unit
): AnchorPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxAnchorPane()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [AnchorPane] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledAnchorPane(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxAnchorPane).() -> Unit
): AnchorPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxAnchorPane()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/src/ktfx/bindings/ObjectValueBinding.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.DoubleBinding
import javafx.beans.binding.FloatBinding
import javafx.beans.binding.IntegerBinding
import javafx.beans.binding.LongBinding
import javafx.beans.binding.ObjectBinding
import javafx.beans.binding.ObjectExpression
import javafx.beans.binding.StringBinding
import javafx.beans.value.ObservableObjectValue
import javafx.beans.value.ObservableValue

/** @see ObjectExpression.isEqualTo */
inline infix fun ObservableObjectValue<*>.eq(other: ObservableObjectValue<*>): BooleanBinding =
    Bindings.equal(this, other)

/** @see ObjectExpression.isEqualTo */
inline infix fun ObservableObjectValue<*>.eq(other: Any): BooleanBinding = Bindings.equal(this, other)

/** @see ObjectExpression.isEqualTo */
inline infix fun Any.eq(other: ObservableObjectValue<*>): BooleanBinding = Bindings.equal(this, other)

/** @see ObjectExpression.isNotEqualTo */
inline infix fun ObservableObjectValue<*>.neq(other: ObservableObjectValue<*>): BooleanBinding =
    Bindings.notEqual(this, other)

/** @see ObjectExpression.isNotEqualTo */
inline infix fun ObservableObjectValue<*>.neq(other: Any): BooleanBinding = Bindings.notEqual(this, other)

/** @see ObjectExpression.isNotEqualTo */
inline infix fun Any.neq(other: ObservableObjectValue<*>): BooleanBinding = Bindings.notEqual(this, other)

/** @see ObjectExpression.isNull */
inline fun ObservableObjectValue<*>.isNull(): BooleanBinding = Bindings.isNull(this)

/** @see ObjectExpression.isNotNull */
inline fun ObservableObjectValue<*>.isNotNull(): BooleanBinding = Bindings.isNotNull(this)

/** Creates an object binding used to get a member. */
inline fun <T> Any.select(vararg steps: String): ObjectBinding<T> = Bindings.select(this, *steps)

/** Creates an object binding used to get a member. */
inline fun <T> ObservableValue<*>.select(vararg steps: String): ObjectBinding<T> = Bindings.select(this, *steps)

/** Creates a string binding used to get a member. */
inline fun Any.selectString(vararg steps: String): StringBinding = Bindings.selectString(this, *steps)

/** Creates a string binding used to get a member. */
inline fun ObservableValue<*>.selectString(vararg steps: String): StringBinding = Bindings.selectString(this, *steps)

/** Creates a boolean binding used to get a member. */
inline fun Any.selectBoolean(vararg steps: String): BooleanBinding = Bindings.selectBoolean(this, *steps)

/** Creates a boolean binding used to get a member. */
inline fun ObservableValue<*>.selectBoolean(vararg steps: String): BooleanBinding = Bindings.selectBoolean(this, *steps)

/** Creates a double binding used to get a member. */
inline fun Any.selectDouble(vararg steps: String): DoubleBinding = Bindings.selectDouble(this, *steps)

/** Creates a double binding used to get a member. */
inline fun ObservableValue<*>.selectDouble(vararg steps: String): DoubleBinding = Bindings.selectDouble(this, *steps)

/** Creates a float binding used to get a member. */
inline fun Any.selectFloat(vararg steps: String): FloatBinding = Bindings.selectFloat(this, *steps)

/** Creates a float binding used to get a member. */
inline fun ObservableValue<*>.selectFloat(vararg steps: String): FloatBinding = Bindings.selectFloat(this, *steps)

/** Creates an integer binding used to get a member. */
inline fun Any.selectInt(vararg steps: String): IntegerBinding = Bindings.selectInteger(this, *steps)

/** Creates an integer binding used to get a member. */
inline fun ObservableValue<*>.selectInt(vararg steps: String): IntegerBinding = Bindings.selectInteger(this, *steps)

/** Creates a long binding used to get a member. */
inline fun Any.selectLong(vararg steps: String): LongBinding = Bindings.selectLong(this, *steps)

/** Creates a long binding used to get a member. */
inline fun ObservableValue<*>.selectLong(vararg steps: String): LongBinding = Bindings.selectLong(this, *steps)


<|start_filename|>ktfx-commons/tests/src/ktfx/inputs/KeyEventTest.kt<|end_filename|>
package ktfx.inputs

import javafx.scene.input.KeyCode
import javafx.scene.input.KeyEvent
import com.hendraanggrian.ktfx.test.BaseInputTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertTrue

@Ignore
class KeyEventTest : BaseInputTest() {

    @Test
    fun isDelete() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.DELETE).isDelete())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.BACK_SPACE).isDelete())
    }

    @Test
    fun is0() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.NUMPAD0).is0())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.SOFTKEY_0).is0())
    }

    @Test
    fun is1() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.NUMPAD1).is1())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.SOFTKEY_1).is1())
    }

    @Test
    fun is2() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.NUMPAD2).is2())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.SOFTKEY_2).is2())
    }

    @Test
    fun is3() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.NUMPAD3).is3())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.SOFTKEY_3).is3())
    }

    @Test
    fun is4() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.NUMPAD4).is4())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.SOFTKEY_4).is4())
    }

    @Test
    fun is5() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.NUMPAD5).is5())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.SOFTKEY_5).is5())
    }

    @Test
    fun is6() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.NUMPAD6).is6())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.SOFTKEY_6).is6())
    }

    @Test
    fun is7() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.NUMPAD7).is7())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.SOFTKEY_7).is7())
    }

    @Test
    fun is8() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.NUMPAD8).is8())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.SOFTKEY_8).is8())
    }

    @Test
    fun is9() {
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.NUMPAD9).is9())
        assertTrue(keyEventOf(KeyEvent.KEY_PRESSED, KeyCode.SOFTKEY_9).is9())
    }
}


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_Transform.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.transform.Transform
import javafx.scene.transform.TransformChangedEvent
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Transform.setOnTransformChanged
 */
public inline fun Transform.onTransformChanged(noinline action: (TransformChangedEvent) -> Unit) {
    return setOnTransformChanged(action)
}


<|start_filename|>testing/listeners-coroutines/src/javafx/scene/web/BaseWebEngineTest.kt<|end_filename|>
package javafx.scene.web

import javafx.geometry.Rectangle2D
import javafx.stage.Stage
import com.hendraanggrian.ktfx.test.testScene
import org.testfx.framework.junit.ApplicationTest
import java.io.IOException
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse

abstract class BaseWebEngineTest : ApplicationTest() {
    private lateinit var engine: WebEngine

    abstract fun WebEngine.callOnAlert(action: (WebEvent<String>) -> Unit)
    abstract fun WebEngine.callOnStatusChanged(action: (WebEvent<String>) -> Unit)
    abstract fun WebEngine.callOnResized(action: (WebEvent<Rectangle2D>) -> Unit)
    abstract fun WebEngine.callOnVisibilityChanged(action: (WebEvent<Boolean>) -> Unit)
    abstract fun WebEngine.callOnError(action: (WebErrorEvent) -> Unit)

    override fun start(stage: Stage) {
        stage.testScene<WebEngine>()
        engine = WebEngine()
    }

    @Test
    fun onAlert() {
        engine.callOnAlert {
            assertEquals(this, it.source)
            assertEquals(WebEvent.ALERT, it.eventType)
            assertEquals("Hello world", it.data)
        }
        engine.onAlert.handle(WebEvent(this, WebEvent.ALERT, "Hello world"))
    }

    @Test
    fun onStatusChanged() {
        engine.callOnStatusChanged {
            assertEquals(this, it.source)
            assertEquals(WebEvent.STATUS_CHANGED, it.eventType)
            assertEquals("Hello world", it.data)
        }
        engine.onStatusChanged.handle(WebEvent(this, WebEvent.STATUS_CHANGED, "Hello world"))
    }

    @Test
    fun onResized() {
        engine.callOnResized {
            assertEquals(this, it.source)
            assertEquals(WebEvent.RESIZED, it.eventType)
            assertEquals(Rectangle2D.EMPTY, it.data)
        }
        engine.onResized.handle(WebEvent(this, WebEvent.RESIZED, Rectangle2D.EMPTY))
    }

    @Test
    fun onVisibilityChanged() {
        engine.callOnVisibilityChanged {
            assertEquals(this, it.source)
            assertEquals(WebEvent.VISIBILITY_CHANGED, it.eventType)
            assertFalse(it.data)
        }
        engine.onVisibilityChanged.handle(WebEvent(this, WebEvent.VISIBILITY_CHANGED, false))
    }

    @Test
    fun onError() {
        engine.callOnError {
            assertEquals(this, it.source)
            assertEquals(WebErrorEvent.USER_DATA_DIRECTORY_IO_ERROR, it.eventType)
            assertEquals("Hello world", it.message)
        }
        engine.onError.handle(
            WebErrorEvent(
                this,
                WebErrorEvent.USER_DATA_DIRECTORY_IO_ERROR,
                "Hello world",
                IOException()
            )
        )
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/CylinderTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.Cylinder
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class CylinderTest : LayoutsTest<KtfxPane, Cylinder>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = cylinder { }
    override fun KtfxPane.child2() = cylinder()
    override fun KtfxPane.child3() = cylinder { }

    override fun Cylinder.testDefaultValues() {
        assertEquals(1.0, radius)
        assertEquals(2.0, height)
        assertEquals(64, divisions)
    }
}

<|start_filename|>testing/listeners-coroutines-controlsfx/src/org/controlsfx/control/BaseNotificationPaneTest.kt<|end_filename|>
package ktfx.controlsfx.test

import com.hendraanggrian.ktfx.test.FakeEventTarget
import com.hendraanggrian.ktfx.test.initToolkit
import javafx.event.Event
import org.controlsfx.control.NotificationPane
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseNotificationPaneTest {
    private lateinit var pane: NotificationPane

    abstract fun NotificationPane.callOnShowing(action: (Event) -> Unit)
    abstract fun NotificationPane.callOnShown(action: (Event) -> Unit)
    abstract fun NotificationPane.callOnHiding(action: (Event) -> Unit)
    abstract fun NotificationPane.callOnHidden(action: (Event) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        pane = NotificationPane()
    }

    @Test
    fun onShowing() {
        pane.callOnShowing {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        pane.onShowing.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onShown() {
        pane.callOnShown {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        pane.onShown.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onHiding() {
        pane.callOnHiding {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        pane.onHiding.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onHidden() {
        pane.callOnHidden {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        pane.onHidden.handle(Event(this, FakeEventTarget, Event.ANY))
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/layout/BorderPaneTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.layout.BorderPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class BorderPaneTest : LayoutsTest<KtfxPane, BorderPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = borderPane { }
    override fun KtfxPane.child2() = borderPane()
    override fun KtfxPane.child3() = borderPane { }
}

<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/dialogs/LoginDialogs.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.dialogs

import javafx.scene.Node
import javafx.scene.image.ImageView
import ktfx.dialogs.graphicIcon
import ktfx.dialogs.headerTitle
import ktfx.toFxPair
import ktfx.toKotlinPair
import org.controlsfx.dialog.LoginDialog
import java.util.Optional

/**
 * Build a login dialog with Kotlin DSL.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param initialUserInfo may be null for empty fields.
 * @param authenticator login callback.
 * @param dialogAction custom dialog action.
 * @return login user and password credential.
 */
fun loginDialog(
    title: String? = null,
    graphic: Node? = null,
    initialUserInfo: Pair<String, String>? = null,
    authenticator: (Pair<String, String>) -> Unit,
    dialogAction: (LoginDialog.() -> Unit)? = null
): Optional<javafx.util.Pair<String, String>> = LoginDialog(
    initialUserInfo?.toFxPair()
) { authenticator(it.toKotlinPair()); null }.also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    dialogAction?.invoke(dialog)
}.showAndWait()

/**
 * Build a login dialog with Kotlin DSL.
 * @param initialUserInfo may be null for empty fields.
 * @param authenticator login callback.
 * @param dialogAction custom dialog action.
 * @return login user and password credential.
 */
inline fun loginDialog(
    initialUserInfo: Pair<String, String>? = null,
    noinline authenticator: (Pair<String, String>) -> Unit,
    noinline dialogAction: (LoginDialog.() -> Unit)? = null
): Optional<javafx.util.Pair<String, String>> = loginDialog(null, null, initialUserInfo, authenticator, dialogAction)


<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXToggleButton.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXToggleButton
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import ktfx.layouts.ToggleButtonManager
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXToggleButton] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.jfxToggleButton(): JFXToggleButton = jfxToggleButton() { }

/**
 * Add a [JFXToggleButton] to this manager.
 *
 * @return the control added.
 */
public fun ToggleButtonManager.jfxToggleButton(): JFXToggleButton = jfxToggleButton() { }

/**
 * Create a [JFXToggleButton] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun jfxToggleButton(configuration: (@KtfxLayoutDslMarker JFXToggleButton).() -> Unit):
    JFXToggleButton {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleButton()
    child.configuration()
    return child
}

/**
 * Add a [JFXToggleButton] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.jfxToggleButton(
    configuration: (
        @KtfxLayoutDslMarker
        JFXToggleButton
    ).() -> Unit
): JFXToggleButton {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleButton()
    child.configuration()
    return addChild(child)
}

/**
 * Add a [JFXToggleButton] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun ToggleButtonManager.jfxToggleButton(
    configuration: (
        @KtfxLayoutDslMarker
        JFXToggleButton
    ).() -> Unit
): JFXToggleButton {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleButton()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXToggleButton].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledJFXToggleButton(vararg styleClass: String, id: String? = null): JFXToggleButton =
    styledJFXToggleButton(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXToggleButton] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledJFXToggleButton(vararg styleClass: String, id: String? = null):
    JFXToggleButton = styledJFXToggleButton(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXToggleButton] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun ToggleButtonManager.styledJFXToggleButton(vararg styleClass: String, id: String? = null):
    JFXToggleButton = styledJFXToggleButton(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [JFXToggleButton] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledJFXToggleButton(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXToggleButton).() -> Unit
): JFXToggleButton {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleButton()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXToggleButton] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledJFXToggleButton(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXToggleButton).() -> Unit
): JFXToggleButton {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleButton()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}

/**
 * Add a styled [JFXToggleButton] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun ToggleButtonManager.styledJFXToggleButton(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXToggleButton).() -> Unit
): JFXToggleButton {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXToggleButton()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/collections/ObservableMapTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.collections.MapChangeListener
import javafx.collections.ObservableMap
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseObservableMapTest

class ObservableMapTest : BaseObservableMapTest() {

    override fun <K, V> ObservableMap<K, V>.callListener(action: (MapChangeListener.Change<out K, out V>) -> Unit) {
        listener<K, V>(Dispatchers.Unconfined) { action(it) }
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXBadgeTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXBadge
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXBadgeTest : LayoutsTest<KtfxPane, JFXBadge>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxBadge { }
    override fun KtfxPane.child2() = jfxBadge()
    override fun KtfxPane.child3() = jfxBadge { }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseTextFieldTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.ActionEvent
import javafx.scene.control.TextField
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseTextFieldTest {

    abstract fun TextField.callOnAction(action: (ActionEvent) -> Unit)

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun onAction() {
        val field = TextField()
        field.callOnAction {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
        }
        field.onAction.handle(ActionEvent(this, FakeEventTarget))
    }
}

<|start_filename|>ktfx-listeners/src/javafx/beans/value/ObservableValue.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.beans.Observable
import javafx.beans.value.ChangeListener
import javafx.beans.value.ObservableValue

/** Adds a [ChangeListener] which will be notified whenever the value of the [ObservableValue] changes. */
inline fun <T> ObservableValue<T>.listener(
    noinline listener: (Observable, oldValue: T, newValue: T) -> Unit
): ChangeListener<T> = ChangeListener<T>(listener).also { addListener(it) }


<|start_filename|>thirdparty/jfoenix-coroutines/tests/src/com/jfoenix/controls/JFXDecoratorTest.kt<|end_filename|>
package ktfx.jfoenix.coroutines

import com.jfoenix.controls.JFXDecorator
import kotlinx.coroutines.Dispatchers
import ktfx.jfoenix.test.BaseJFXDecoratorTest

class JFXDecoratorTest : BaseJFXDecoratorTest() {

    override fun JFXDecorator.callOnCloseButtonAction(action: () -> Unit) =
        onCloseButtonAction(Dispatchers.Unconfined) { action() }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_DatePicker.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.DatePicker
import java.time.LocalDate
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [DatePicker] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.datePicker(date: LocalDate? = null): DatePicker = datePicker(date = date) { }

/**
 * Create a [DatePicker] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun datePicker(
    date: LocalDate? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        DatePicker
    ).() -> Unit
): DatePicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = DatePicker(date)
    child.configuration()
    return child
}

/**
 * Add a [DatePicker] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.datePicker(
    date: LocalDate? = null,
    configuration: (@KtfxLayoutDslMarker DatePicker).() -> Unit
): DatePicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = DatePicker(date)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [DatePicker].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledDatePicker(
    date: LocalDate? = null,
    vararg styleClass: String,
    id: String? = null
): DatePicker = styledDatePicker(date = date, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [DatePicker] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledDatePicker(
    date: LocalDate? = null,
    vararg styleClass: String,
    id: String? = null
): DatePicker = styledDatePicker(date = date, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [DatePicker] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledDatePicker(
    date: LocalDate? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker DatePicker).() -> Unit
): DatePicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = DatePicker(date)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [DatePicker] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledDatePicker(
    date: LocalDate? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker DatePicker).() -> Unit
): DatePicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = DatePicker(date)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/controls/TableColumnsTest.kt<|end_filename|>
package ktfx.controls

import com.hendraanggrian.ktfx.test.initToolkit
import javafx.scene.control.TableView
import javafx.scene.control.TreeTableView
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

class TableColumnsTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun tableView() {
        val table = TableView<Nothing>()
        table.columns {
            "Full name"<String> {
                columns {
                    append<String>("First name")
                    append<String>("Last name")
                }
            }
            append<Int>("Age")
        }
        assertEquals(table.columns[0].text, "Full name")
        assertEquals(table.columns[0].columns[0].text, "First name")
        assertEquals(table.columns[0].columns[1].text, "Last name")
        assertEquals(table.columns[1].text, "Age")
    }

    @Test
    fun treeTableView() {
        val treeTable = TreeTableView<Nothing>()
        treeTable.columns {
            "Full name"<String> {
                columns {
                    append<String>("First name")
                    append<String>("Last name")
                }
            }
            append<Int>("Age")
        }
        assertEquals(treeTable.columns[0].text, "Full name")
        assertEquals(treeTable.columns[0].columns[0].text, "First name")
        assertEquals(treeTable.columns[0].columns[1].text, "Last name")
        assertEquals(treeTable.columns[1].text, "Age")
    }
}


<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseComboBoxBaseTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.ComboBox
import javafx.scene.control.ComboBoxBase
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseComboBoxBaseTest {
    private lateinit var combo: ComboBoxBase<String>

    abstract fun <E> ComboBoxBase<E>.callOnAction(action: (ActionEvent) -> Unit)
    abstract fun <E> ComboBoxBase<E>.callOnShowing(action: (Event) -> Unit)
    abstract fun <E> ComboBoxBase<E>.callOnShown(action: (Event) -> Unit)
    abstract fun <E> ComboBoxBase<E>.callOnHiding(action: (Event) -> Unit)
    abstract fun <E> ComboBoxBase<E>.callOnHidden(action: (Event) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        combo = ComboBox()
    }

    @Test
    fun onAction() {
        combo.callOnAction {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
        }
        combo.onAction.handle(ActionEvent(this, FakeEventTarget))
    }

    @Test
    fun onShowing() {
        combo.callOnShowing {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        combo.onShowing.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onShown() {
        combo.callOnShown {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        combo.onShown.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onHiding() {
        combo.callOnHiding {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        combo.onHiding.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onHidden() {
        combo.callOnHidden {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        combo.onHidden.handle(Event(this, FakeEventTarget, Event.ANY))
    }
}

<|start_filename|>thirdparty/controlsfx-listeners/src/ktfx/controlsfx/listeners/_BreadCrumbBar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.listeners

import org.controlsfx.control.BreadCrumbBar
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see BreadCrumbBar.setOnCrumbAction
 */
public inline fun <T> BreadCrumbBar<T>.onCrumbAction(
    noinline
    action: (BreadCrumbBar.BreadCrumbActionEvent<T>) -> Unit
) {
    return setOnCrumbAction(action)
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Cylinder.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.Cylinder
import kotlin.Double
import kotlin.Int
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [Cylinder] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.cylinder(
    radius: Double = 1.0,
    height: Double = 2.0,
    division: Int = 64
): Cylinder = cylinder(radius = radius, height = height, division = division) { }

/**
 * Create a [Cylinder] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun cylinder(
    radius: Double = 1.0,
    height: Double = 2.0,
    division: Int = 64,
    configuration: (@KtfxLayoutDslMarker Cylinder).() -> Unit
): Cylinder {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Cylinder(radius, height, division)
    child.configuration()
    return child
}

/**
 * Add a [Cylinder] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.cylinder(
    radius: Double = 1.0,
    height: Double = 2.0,
    division: Int = 64,
    configuration: (@KtfxLayoutDslMarker Cylinder).() -> Unit
): Cylinder {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Cylinder(radius, height, division)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Cylinder].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledCylinder(
    radius: Double = 1.0,
    height: Double = 2.0,
    division: Int = 64,
    vararg styleClass: String,
    id: String? = null
): Cylinder = styledCylinder(
    radius = radius, height = height, division = division,
    styleClass =
    *styleClass,
    id = id
) { }

/**
 * Add a styled [Cylinder] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledCylinder(
    radius: Double = 1.0,
    height: Double = 2.0,
    division: Int = 64,
    vararg styleClass: String,
    id: String? = null
): Cylinder = styledCylinder(
    radius = radius, height = height, division = division,
    styleClass =
    *styleClass,
    id = id
) { }

/**
 * Create a styled [Cylinder] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledCylinder(
    radius: Double = 1.0,
    height: Double = 2.0,
    division: Int = 64,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Cylinder).() -> Unit
): Cylinder {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Cylinder(radius, height, division)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Cylinder] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledCylinder(
    radius: Double = 1.0,
    height: Double = 2.0,
    division: Int = 64,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Cylinder).() -> Unit
): Cylinder {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Cylinder(radius, height, division)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/ButtonBaseTest.kt<|end_filename|>
package ktfx.listeners

import javafx.event.ActionEvent
import javafx.scene.control.ButtonBase
import com.hendraanggrian.ktfx.test.BaseButtonBaseTest

class ButtonBaseTest : BaseButtonBaseTest() {

    override fun ButtonBase.callOnAction(action: (ActionEvent) -> Unit) = onAction(action)
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_TableView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.collections.FXCollections.observableArrayList
import javafx.collections.ObservableList
import javafx.scene.control.TableView
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [TableView] to this manager.
 *
 * @return the control added.
 */
public fun <S> NodeManager.tableView(items: ObservableList<S> = observableArrayList()): TableView<S> =
    tableView(items = items) { }

/**
 * Create a [TableView] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun <S> tableView(
    items: ObservableList<S> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker TableView<S>).() -> Unit
): TableView<S> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TableView<S>(items)
    child.configuration()
    return child
}

/**
 * Add a [TableView] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun <S> NodeManager.tableView(
    items: ObservableList<S> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker TableView<S>).() -> Unit
): TableView<S> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TableView<S>(items)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [TableView].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun <S> styledTableView(
    items: ObservableList<S> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): TableView<S> = styledTableView(items = items, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [TableView] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun <S> NodeManager.styledTableView(
    items: ObservableList<S> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): TableView<S> = styledTableView(items = items, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [TableView] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun <S> styledTableView(
    items: ObservableList<S> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker TableView<S>).() -> Unit
): TableView<S> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TableView<S>(items)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [TableView] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun <S> NodeManager.styledTableView(
    items: ObservableList<S> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker TableView<S>).() -> Unit
): TableView<S> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TableView<S>(items)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/controlsfx-coroutines/src/ktfx/controlsfx/coroutines/_HyperlinkLabel.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxCoroutinesKt")

package ktfx.controlsfx.coroutines

import javafx.event.ActionEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import org.controlsfx.control.HyperlinkLabel
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see HyperlinkLabel.setOnAction
 */
public fun HyperlinkLabel.onAction(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ActionEvent) -> Unit
) {
    return setOnAction { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/TextFieldTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.event.ActionEvent
import javafx.scene.control.TextField
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseTextFieldTest

class TextFieldTest : BaseTextFieldTest() {

    override fun TextField.callOnAction(action: (ActionEvent) -> Unit) =
        onAction(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXComboBoxTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.google.common.truth.Truth.assertThat
import com.jfoenix.controls.JFXComboBox
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXComboBoxTest : LayoutsTest<KtfxPane, JFXComboBox<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxComboBox<String> { }
    override fun KtfxPane.child2() = jfxComboBox<String>()
    override fun KtfxPane.child3() = jfxComboBox<String> { }

    override fun JFXComboBox<String>.testDefaultValues() {
        assertThat(items).isEmpty()
    }
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_Window.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.stage.Window
import javafx.stage.WindowEvent
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Window.setOnCloseRequest
 */
public inline fun Window.onCloseRequest(noinline action: (WindowEvent) -> Unit) {
    return setOnCloseRequest(action)
}

/**
 * @see Window.setOnShowing
 */
public inline fun Window.onShowing(noinline action: (WindowEvent) -> Unit) {
    return setOnShowing(action)
}

/**
 * @see Window.setOnShown
 */
public inline fun Window.onShown(noinline action: (WindowEvent) -> Unit) {
    return setOnShown(action)
}

/**
 * @see Window.setOnHiding
 */
public inline fun Window.onHiding(noinline action: (WindowEvent) -> Unit) {
    return setOnHiding(action)
}

/**
 * @see Window.setOnHidden
 */
public inline fun Window.onHidden(noinline action: (WindowEvent) -> Unit) {
    return setOnHidden(action)
}


<|start_filename|>ktfx-listeners/src/javafx/scene/control/TableColumnBase.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.scene.control.TableColumnBase

/** Registers an event handler to this table column. */
inline fun <E : Event> TableColumnBase<*, *>.eventHandler(
    type: EventType<E>,
    noinline action: (Event) -> Unit
): EventHandler<E> = EventHandler<E>(action)
    .also { addEventHandler(type, it) }


<|start_filename|>thirdparty/jfoenix-listeners/tests/src/com/jfoenix/controls/JFXDrawerTest.kt<|end_filename|>
package ktfx.jfoenix.listeners

import com.jfoenix.controls.JFXDrawer
import com.jfoenix.controls.events.JFXDrawerEvent
import ktfx.jfoenix.test.BaseJFXDrawerTest

class JFXDrawerTest : BaseJFXDrawerTest() {

    override fun JFXDrawer.callOnDrawerClosed(action: (JFXDrawerEvent) -> Unit) = onDrawerClosed(action)
    override fun JFXDrawer.callOnDrawerClosing(action: (JFXDrawerEvent) -> Unit) = onDrawerClosing(action)
    override fun JFXDrawer.callOnDrawerOpened(action: (JFXDrawerEvent) -> Unit) = onDrawerOpened(action)
    override fun JFXDrawer.callOnDrawerOpening(action: (JFXDrawerEvent) -> Unit) = onDrawerOpening(action)
}

<|start_filename|>ktfx-commons/src/ktfx/text/TextFlow.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.text

import javafx.scene.text.Text
import javafx.scene.text.TextFlow

/**
 * Sets the character at the specified [index] to the specified [value].
 * @see kotlin.text.set
 */
operator fun TextFlow.set(index: Int, value: String) {
    val child = children[index]
    require(child is Text) { "TextFlow child is not a Text." }
    child.text = value
}

/**
 * Clears the content of this flow making it empty.
 * @see kotlin.text.clear
 */
inline fun TextFlow.clear(): TextFlow = apply { children.clear() }

/**
 * Appends [value] to this flow.
 * @see java.lang.Appendable.append
 */
fun TextFlow.append(value: String?): TextFlow = apply { children += Text(value ?: "null") }

/**
 * Appends [value] to this flow.
 * @see java.lang.StringBuilder.append
 */
fun TextFlow.append(value: Any?): TextFlow = append(value?.toString())

/**
 * Appends a line separator to this flow.
 * @see kotlin.text.appendLine
 */
fun TextFlow.appendLine(): TextFlow = append(SystemProperties.LINE_SEPARATOR)

/**
 * Appends [value] to this flow, followed by a line separator.
 * @see kotlin.text.appendLine
 */
inline fun TextFlow.appendLine(value: String?): TextFlow = append(value).appendLine()

/**
 * Appends [value] to this flow, followed by a line separator.
 * @see kotlin.text.appendLine
 */
inline fun TextFlow.appendLine(value: Any?): TextFlow = append(value).appendLine()

/**
 * @see kotlin.text.SystemProperties
 */
private object SystemProperties {
    /** Line separator for current system. */
    @JvmField
    val LINE_SEPARATOR = checkNotNull(System.getProperty("line.separator")) { "Unable to obtain separator character." }
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/WorldMapViewTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.WorldMapView

class WorldMapViewTest : LayoutsTest<KtfxPane, WorldMapView>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = worldMapView { }
    override fun KtfxPane.child2() = worldMapView()
    override fun KtfxPane.child3() = worldMapView { }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseMenuItemTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.MenuItem
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseMenuItemTest {
    private lateinit var item: MenuItem

    abstract fun MenuItem.callOnAction(action: (ActionEvent) -> Unit)
    abstract fun MenuItem.callOnMenuValidation(action: (Event) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        item = MenuItem()
    }

    @Test
    fun onAction() {
        item.callOnAction {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
        }
        item.onAction.handle(ActionEvent(this, FakeEventTarget))
    }

    @Test
    fun onMenuValidation() {
        item.callOnMenuValidation {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        item.onMenuValidation.handle(Event(this, FakeEventTarget, Event.ANY))
    }
}

<|start_filename|>rulesets/basic/build.gradle.kts<|end_filename|>
plugins {
    kotlin("jvm")
}

sourceSets {
    main {
        java.srcDir("src")
        resources.srcDir("res")
    }
    test {
        java.srcDir("tests/src")
    }
}

dependencies {
    implementation(kotlin("stdlib", VERSION_KOTLIN))
    implementation(kotlin("test-junit", VERSION_KOTLIN))
    implementation(ktlint("core"))
    testImplementation(project(":testing:ruleset"))
}

<|start_filename|>ktfx-listeners/src/javafx/collections/ObservableList.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.collections.ListChangeListener
import javafx.collections.ListChangeListener.Change
import javafx.collections.ObservableList

/** Add a listener to this observable list. */
inline fun <E> ObservableList<E>.listener(
    noinline listener: (Change<out E>) -> Unit
): ListChangeListener<E> = ListChangeListener<E>(listener).also { addListener(it) }


<|start_filename|>thirdparty/controlsfx-listeners/build.gradle.kts<|end_filename|>
group = RELEASE_GROUP
version = RELEASE_VERSION

plugins {
    javafx
    kotlin("jvm")
    dokka
    `maven-publish`
    signing
}

javafx {
    modules("javafx.controls")
}

sourceSets {
    main {
        java.srcDir("src")
    }
    test {
        java.srcDir("tests/src")
    }
}

ktlint(
    project(":rulesets:basic"),
    project(":rulesets:non-commons")
)

dependencies {
    api(project(":$RELEASE_ARTIFACT-listeners"))
    api(controlsfx())
    testImplementation(project(":testing:listeners-coroutines-controlsfx"))
}

tasks {
    dokkaJavadoc {
        dokkaSourceSets {
            "main" {
                sourceLink {
                    localDirectory.set(projectDir.resolve("src"))
                    remoteUrl.set(getGithubRemoteUrl())
                    remoteLineSuffix.set("#L")
                }
            }
        }
    }
    dokkaHtml {
        outputDirectory.set(buildDir.resolve("dokka/controlsfx-listeners"))
    }
}

mavenPublishJvm("controlsfx-listeners")

<|start_filename|>ktfx-layouts/src/javafx/scene/layout/KtfxVBox.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.layouts

import javafx.geometry.Insets
import javafx.scene.Node
import javafx.scene.layout.Priority
import javafx.scene.layout.VBox
import kotlin.contracts.ExperimentalContracts

/**
 * [VBox] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxVBox(spacing: Double) : VBox(spacing), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { children += it }

    /** Children vertical grow priority in this layout. */
    inline var Node.vgrow: Priority?
        @JvmName("getVgrow2") get() = getVgrow(this)
        @JvmName("setVgrow2") set(value) = setVgrow(this, value)

    /** Configure [vgrow] fluidly. */
    fun <C : Node> C.vgrow(always: Boolean = true): C {
        vgrow = if (always) Priority.ALWAYS else Priority.NEVER
        return this
    }

    /** Children margin in this layout. */
    inline var Node.margin: Insets?
        @JvmName("getMargin2") get() = getMargin(this)
        @JvmName("setMargin2") set(value) = setMargin(this, value)

    /** Configure [margin] fluidly. */
    fun <C : Node> C.margin(insets: Insets): C {
        margin = insets
        return this
    }

    /** Clear children constraints. */
    @JvmName("clearConstraints2")
    inline fun Node.clearConstraints(): Unit = clearConstraints(this)
}


<|start_filename|>ktfx-layouts/src/javafx/scene/shape/KtfxPath.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.Path
import javafx.scene.shape.PathElement
import kotlin.contracts.ExperimentalContracts

/**
 * [Path] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxPath : Path(), PathElementManager {

    final override fun <C : PathElement> addChild(child: C): C = child.also { elements += it }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/CheckMenuItemTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.CheckMenuItem
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class CheckMenuItemTest : LayoutsTest<KtfxMenu, CheckMenuItem>() {

    override fun manager() = KtfxMenu("", null)
    override fun KtfxMenu.childCount() = items.size
    override fun child1() = checkMenuItem { }
    override fun KtfxMenu.child2() = checkMenuItem()
    override fun KtfxMenu.child3() = checkMenuItem { }

    override fun CheckMenuItem.testDefaultValues() {
        assertNull(text)
        assertNull(graphic)
    }
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/media/MediaViewTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.media.MediaErrorEvent
import javafx.scene.media.MediaView
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseMediaViewTest

class MediaViewTest : BaseMediaViewTest() {

    override fun MediaView.callOnError(action: (MediaErrorEvent) -> Unit) =
        onError(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/dialogs/DialogTest.kt<|end_filename|>
package ktfx.dialogs

import com.google.common.truth.Truth.assertThat
import javafx.scene.control.Dialog
import ktfx.windows.stage
import com.hendraanggrian.ktfx.test.DialogShowingTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue

@Ignore
class DialogTest : DialogShowingTest() {

    @Test
    fun graphicIcon() {
        interact {
            val dialog = Dialog<Nothing>()
            assertThat(dialog.dialogPane.scene.stage.icons).isEmpty()
            assertNull(dialog.graphic)
            dialog.graphicIcon = sampleGraphic
            assertThat(dialog.dialogPane.scene.stage.icons).isNotEmpty()
            assertEquals(sampleGraphic, dialog.graphic)
        }
    }

    @Test
    fun headerTitle() {
        interact {
            val dialog = Dialog<Nothing>()
            assertNull(dialog.headerText)
            assertNull(dialog.title)
            dialog.headerTitle = "Hello World"
            assertEquals("Hello World", dialog.headerText)
            assertEquals("Hello World", dialog.title)
        }
    }

    /** Because some dialog texts have space suffix, use [assertTrue] instead of [assertEquals]. */
    @Test
    fun buttons() {
        interact {
            val dialog = Dialog<Nothing>()

            dialog.buttons.apply()
            assertEquals(1, dialog.dialogPane.buttonTypes.size)

            dialog.dialogPane.buttonTypes.clear()
            dialog.buttons {
                apply { assertTrue("Apply" in text) }
                ok { assertTrue("OK" in text) }
                cancel { assertTrue("Cancel" in text) }
                close { assertTrue("Close" in text) }
                yes { assertTrue("Yes" in text) }
                no { assertTrue("No" in text) }
                finish { assertTrue("Finish" in text) }
                next { assertTrue("Next" in text) }
                previous { assertTrue("Previous" in text) }
                custom("Custom1") { assertEquals("Custom1", text) }
                "Custom2" { assertEquals("Custom2", text) }
            }
            assertEquals(11, dialog.dialogPane.buttonTypes.size)
        }
    }
}


<|start_filename|>testing/listeners-coroutines/src/com/hendraanggrian/ktfx/test/events/FakeZoomEvent.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.EventType
import javafx.scene.input.ZoomEvent
import kotlin.test.assertEquals
import kotlin.test.assertFalse

/**
 * @receiver source of this fake event.
 */
fun Any.assertFakeZoomEvent(actual: ZoomEvent, expectedType: EventType<ZoomEvent>) {
    assertEquals(this, actual.source)
    assertEquals(FakeEventTarget, actual.target)
    assertEquals(expectedType, actual.eventType)
    assertEquals(0.0, actual.x)
    assertEquals(0.0, actual.y)
    assertEquals(0.0, actual.screenX)
    assertEquals(0.0, actual.screenY)
    assertFalse(actual.isShiftDown)
    assertFalse(actual.isControlDown)
    assertFalse(actual.isAltDown)
    assertFalse(actual.isMetaDown)
    assertFalse(actual.isDirect)
    assertFalse(actual.isInertia)
    assertEquals(0.0, actual.zoomFactor)
    assertEquals(0.0, actual.totalZoomFactor)
    assertEquals(FakePickResult, actual.pickResult)
}

/**
 * @receiver source of this fake event.
 */
fun Any.fakeZoomEventOf(eventType: EventType<ZoomEvent>) = ZoomEvent(
    this, FakeEventTarget, eventType,
    0.0, 0.0,
    0.0, 0.0,
    false,
    false,
    false,
    false,
    false,
    false,
    0.0,
    0.0,
    FakePickResult
)

<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/ObjectValueBindingTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.propertyOf
import ktfx.time.minutes
import ktfx.time.seconds
import java.time.Duration
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class ObjectValueBindingTest {

    @Test
    fun eq() {
        assertFalse((propertyOf<Duration>() eq propertyOf(1.minutes)).value)
        assertTrue((propertyOf(60.seconds) eq propertyOf(1.minutes)).value)
    }

    @Test
    fun neq() {
        assertTrue((propertyOf<Duration>() neq propertyOf(1.minutes)).value)
        assertFalse((propertyOf(60.seconds) neq propertyOf(1.minutes)).value)
    }
}


<|start_filename|>ktfx-commons/src/ktfx/controls/Insets.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controls

import javafx.geometry.Insets

/** Empty insets. An [Insets] instance with all offsets equal to zero. */
inline fun insetsOf(): Insets = Insets.EMPTY

/** Create an inset where [Int] number will be applied to all side. */
fun insetsOf(all: Int): Insets = insetsOf(all.toDouble())

/** Create an inset where [Long] number will be applied to all side. */
fun insetsOf(all: Long): Insets = insetsOf(all.toDouble())

/** Create an inset where [Double] number will be applied to all side. */
inline fun insetsOf(all: Double): Insets = Insets(all)

/** Create an inset where [Int] number will be applied to both side. */
fun insetsOf(vertical: Int = 0, horizontal: Int = 0): Insets =
    insetsOf(vertical.toDouble(), horizontal.toDouble())

/** Create an inset where [Long] number will be applied to both side. */
fun insetsOf(vertical: Long = 0, horizontal: Long = 0): Insets =
    insetsOf(vertical.toDouble(), horizontal.toDouble())

/** Create an inset where [Double] number will be applied to both side. */
inline fun insetsOf(vertical: Double = 0.0, horizontal: Double = 0.0): Insets =
    Insets(vertical, horizontal, vertical, horizontal)

/** Create an inset where [Int] number will be applied to each side. */
fun insetsOf(top: Int = 0, right: Int = 0, bottom: Int = 0, left: Int = 0): Insets =
    insetsOf(top.toDouble(), right.toDouble(), bottom.toDouble(), left.toDouble())

/** Create an inset where [Long] number will be applied to each side. */
fun insetsOf(top: Long = 0L, right: Long = 0L, bottom: Long = 0L, left: Long = 0L): Insets =
    insetsOf(top.toDouble(), right.toDouble(), bottom.toDouble(), left.toDouble())

/** Create an inset where [Double] number will be applied to each side. */
inline fun insetsOf(top: Double = 0.0, right: Double = 0.0, bottom: Double = 0.0, left: Double = 0.0): Insets =
    Insets(top, right, bottom, left)


<|start_filename|>testing/listeners-coroutines/src/javafx/collections/BaseObservableArrayTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.beans.Observable
import javafx.collections.FXCollections
import javafx.collections.ObservableArray
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

abstract class BaseObservableArrayTest {

    abstract fun <T : ObservableArray<T>> ObservableArray<T>.callListener(action: (Observable, Boolean, Int, Int) -> Unit)

    @Test
    fun listener() {
        val array = FXCollections.observableIntegerArray()
        array.callListener { observable, changed, from, to ->
            assertEquals(observable, array)
            assertTrue(changed)
            assertEquals(0, from)
            assertEquals(1, to)
        }
        array.addAll(1)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/PolylineTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.shape.Polyline
import com.hendraanggrian.ktfx.test.LayoutsTest

class PolylineTest : LayoutsTest<KtfxPane, Polyline>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = polyline { }
    override fun KtfxPane.child2() = polyline()
    override fun KtfxPane.child3() = polyline { }

    override fun Polyline.testDefaultValues() {
        assertThat(points).isEmpty()
    }
}

<|start_filename|>ktfx-layouts/src/javafx/scene/Scene.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Scene
import javafx.scene.layout.Pane
import javafx.scene.paint.Color
import javafx.scene.paint.Paint
import javafx.stage.Stage
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/** Create a [Scene] with configuration block. */
inline fun scene(
    width: Double = -1.0,
    height: Double = -1.0,
    fill: Paint = Color.WHITE,
    configuration: (@KtfxLayoutDslMarker KtfxScene).() -> Unit
): Scene {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return KtfxScene(Pane(), width, height, fill).apply(configuration)
}

/** Add a [Scene] to this window. */
fun Stage.scene(
    width: Double = -1.0,
    height: Double = -1.0,
    fill: Paint = Color.WHITE
): Scene = KtfxScene(Pane(), width, height, fill).also { scene = it }

/** Add a [Scene] with configuration block to this window. */
inline fun Stage.scene(
    width: Double = -1.0,
    height: Double = -1.0,
    fill: Paint = Color.WHITE,
    configuration: (@KtfxLayoutDslMarker KtfxScene).() -> Unit
): Scene {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return ktfx.layouts.scene(width, height, fill, configuration).also { scene = it }
}


<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_SegmentedBar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.SegmentedBar
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [SegmentedBar] to this manager.
 *
 * @return the control added.
 */
public fun <T : SegmentedBar.Segment> NodeManager.segmentedBar(): SegmentedBar<T> = segmentedBar() {
}

/**
 * Create a [SegmentedBar] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun <T : SegmentedBar.Segment> segmentedBar(
    configuration: (
        @KtfxLayoutDslMarker
        SegmentedBar<T>
    ).() -> Unit
): SegmentedBar<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = SegmentedBar<T>()
    child.configuration()
    return child
}

/**
 * Add a [SegmentedBar] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun <T : SegmentedBar.Segment>
NodeManager.segmentedBar(configuration: (@KtfxLayoutDslMarker SegmentedBar<T>).() -> Unit):
    SegmentedBar<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = SegmentedBar<T>()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [SegmentedBar].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun <T : SegmentedBar.Segment> styledSegmentedBar(
    vararg styleClass: String,
    id: String? =    
        null
): SegmentedBar<T> = styledSegmentedBar(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [SegmentedBar] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun <T : SegmentedBar.Segment> NodeManager.styledSegmentedBar(
    vararg styleClass: String,
    id: String? = null
): SegmentedBar<T> = styledSegmentedBar(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [SegmentedBar] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun <T : SegmentedBar.Segment> styledSegmentedBar(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker SegmentedBar<T>).() -> Unit
): SegmentedBar<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = SegmentedBar<T>()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [SegmentedBar] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun <T : SegmentedBar.Segment> NodeManager.styledSegmentedBar(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker SegmentedBar<T>).() -> Unit
): SegmentedBar<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = SegmentedBar<T>()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/MenuButtonTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.control.MenuButton
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class MenuButtonTest : LayoutsTest<KtfxPane, MenuButton>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = menuButton { }
    override fun KtfxPane.child2() = menuButton()
    override fun KtfxPane.child3() = menuButton { }

    override fun MenuButton.testDefaultValues() {
        assertEquals("", text)
        assertNull(graphic)
    }

    @Test
    fun stringInvocation() {
        menuButton {
            assertThat(items).isEmpty()
            menuItem("Hello")
            "World" {
            }
            // TODO("find out why line below throws error")
            // assertEquals(2, items.size)
        }
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/CheckListViewTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import com.google.common.truth.Truth.assertThat
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.CheckListView

class CheckListViewTest : LayoutsTest<KtfxPane, CheckListView<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = checkListView<String> { }
    override fun KtfxPane.child2() = checkListView<String>()
    override fun KtfxPane.child3() = checkListView<String> { }

    override fun CheckListView<String>.testDefaultValues() {
        assertThat(items).isEmpty()
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/HyperlinkTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.Hyperlink
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class HyperlinkTest : LayoutsTest<KtfxPane, Hyperlink>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = hyperlink { }
    override fun KtfxPane.child2() = hyperlink()
    override fun KtfxPane.child3() = hyperlink { }

    override fun Hyperlink.testDefaultValues() {
        assertNull(text)
        assertNull(graphic)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/PathTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.Path
import com.hendraanggrian.ktfx.test.LayoutsTest

class PathTest : LayoutsTest<KtfxPane, Path>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = path { }
    override fun KtfxPane.child2() = path()
    override fun KtfxPane.child3() = path { }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/org/controlsfx/control/KtfxMasterDetailPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import javafx.geometry.Side
import javafx.scene.Node
import ktfx.layouts.NodeManager
import org.controlsfx.control.MasterDetailPane
import kotlin.contracts.ExperimentalContracts

/**
 * [MasterDetailPane] with dynamic-layout dsl support.
 * Invoking dsl will only set its master and detail, in order.
 */
open class KtfxMasterDetailPane(detailSide: Side, showDetail: Boolean) :
    MasterDetailPane(detailSide, showDetail), NodeManager {
    private var size = 0

    final override fun <C : Node> addChild(child: C): C =
        child.also {
            when (size++) {
                0 -> masterNode = it
                1 -> detailNode = it
                else -> error("Master and detail node has been set.")
            }
        }
}


<|start_filename|>testing/listeners-coroutines-jfoenix/src/com/jfoenix/controls/BaseJFXAutoCompletePopupTest.kt<|end_filename|>
package ktfx.jfoenix.test

import com.hendraanggrian.ktfx.test.initToolkit
import com.jfoenix.controls.JFXAutoCompletePopup
import com.jfoenix.controls.events.JFXAutoCompleteEvent
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseJFXAutoCompletePopupTest {
    private lateinit var popup: JFXAutoCompletePopup<String>

    abstract fun <E> JFXAutoCompletePopup<E>.callSelectionHandler(action: (JFXAutoCompleteEvent<E>) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        popup = JFXAutoCompletePopup()
    }

    @Test
    fun selectionHandler() {
        popup.callSelectionHandler {
            assertEquals(JFXAutoCompleteEvent.SELECTION, it.eventType)
            assertEquals("Hello world", it.`object`)
        }
        popup.selectionHandler.handle(JFXAutoCompleteEvent(JFXAutoCompleteEvent.SELECTION, "Hello world"))
    }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/concurrent/ServiceTest.kt<|end_filename|>
package ktfx.listeners

import javafx.concurrent.Service
import javafx.concurrent.WorkerStateEvent
import com.hendraanggrian.ktfx.test.BaseServiceTest

class ServiceTest : BaseServiceTest() {

    override fun <E> Service<E>.callOnReady(action: (WorkerStateEvent) -> Unit) = onReady(action)
    override fun <E> Service<E>.callOnScheduled(action: (WorkerStateEvent) -> Unit) = onScheduled(action)
    override fun <E> Service<E>.callOnRunning(action: (WorkerStateEvent) -> Unit) = onRunning(action)
    override fun <E> Service<E>.callOnSucceeded(action: (WorkerStateEvent) -> Unit) = onSucceeded(action)
    override fun <E> Service<E>.callOnCancelled(action: (WorkerStateEvent) -> Unit) = onCancelled(action)
    override fun <E> Service<E>.callOnFailed(action: (WorkerStateEvent) -> Unit) = onFailed(action)
}

<|start_filename|>ktfx-commons/tests/src/ktfx/controls/SwingUtilsTest.kt<|end_filename|>
package ktfx.controls

import javafx.scene.image.WritableImage
import java.awt.image.BufferedImage
import kotlin.test.Test
import kotlin.test.assertEquals

class SwingUtilsTest {
    private companion object {
        const val WIDTH: Int = 1000
        const val HEIGHT: Int = 500
    }

    @Test
    fun toFxImage() {
        val image = BufferedImage(
            WIDTH,
            HEIGHT, BufferedImage.TYPE_INT_ARGB).toFxImage()
        assertEquals(WIDTH, image.width.toInt())
        assertEquals(HEIGHT, image.height.toInt())
    }

    @Test
    fun toSwingImage() {
        val image = WritableImage(
            WIDTH,
            HEIGHT
        ).toSwingImage()
        assertEquals(WIDTH, image.width)
        assertEquals(HEIGHT, image.height)
    }
}


<|start_filename|>ktfx-commons/tests/src/com/hendraanggrian/ktfx/test/BaseMapTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import kotlin.test.assertFails

abstract class BaseMapTest<T : MutableMap<String, Any?>> {

    private companion object {
        const val SINGLETON_VALUE = "Lonely text"
        val FILL_VALUES = arrayOf("I'm", "a", "little", "piggy")
        const val ADD_VALUE = "Oink"

        val MAP = mapOf(*FILL_VALUES.map { it to null }.toTypedArray())
    }

    abstract fun empty(): T
    abstract fun of(): T
    abstract fun of(value: String): T
    abstract fun of(vararg values: String): T
    abstract fun mutableOf(): T
    abstract fun mutableOf(vararg values: String): T

    @Test
    fun creating() {
        val empty = empty()
        assertThat(empty.keys).isEmpty()
        assertFails { empty[ADD_VALUE] = null }

        val unfilled = of()
        assertThat(unfilled.keys).isEmpty()
        assertFails { unfilled[ADD_VALUE] = null }

        val singleton = of(SINGLETON_VALUE)
        assertThat(singleton.keys).containsExactly(SINGLETON_VALUE)
        assertFails { singleton[ADD_VALUE] = null }

        val filled = of(*FILL_VALUES)
        assertThat(filled.keys).containsExactly(*FILL_VALUES)
        assertFails { filled[ADD_VALUE] = null }

        val mutableUnfilled = mutableOf()
        mutableUnfilled[ADD_VALUE] = null
        assertThat(mutableUnfilled.keys).containsExactly(ADD_VALUE)

        val mutableFilled = mutableOf(*FILL_VALUES)
        mutableFilled[ADD_VALUE] = null
        assertThat(mutableFilled.keys).containsExactly(*FILL_VALUES, ADD_VALUE)
    }

    abstract fun Map<String, Any?>.to(): T
    abstract fun Map<String, Any?>.toMutable(): T

    @Test
    fun converting() {
        val fromArray = MAP.to()
        assertThat(fromArray.keys).containsExactly(*FILL_VALUES)
        assertFails { fromArray[ADD_VALUE] = null }

        val mutableFromArray = MAP.toMutable()
        mutableFromArray[ADD_VALUE] = null
        assertThat(mutableFromArray.keys).containsExactly(*FILL_VALUES, ADD_VALUE)
    }
}


<|start_filename|>testing/listeners-coroutines-controlsfx/src/org/controlsfx/control/BaseHyperlinkLabelTest.kt<|end_filename|>
package ktfx.controlsfx.test

import com.hendraanggrian.ktfx.test.FakeEventTarget
import com.hendraanggrian.ktfx.test.initToolkit
import javafx.event.ActionEvent
import org.controlsfx.control.HyperlinkLabel
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseHyperlinkLabelTest {
    private lateinit var label: HyperlinkLabel

    abstract fun HyperlinkLabel.callOnAction(action: (ActionEvent) -> Unit)

    @BeforeTest
    fun create() {
        initToolkit()
        label = HyperlinkLabel()
    }

    @Test
    fun onAction() {
        label.callOnAction {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
        }
        label.onAction.handle(ActionEvent(this, FakeEventTarget))
    }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/PropertiesTest.kt<|end_filename|>
package ktfx

import javafx.beans.property.ReadOnlyObjectWrapper
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse

class PropertiesTest {

    @Test
    fun boolean() {
        assertFalse(propertyOf(false).asPrimitive().value)
        assertFalse(ReadOnlyObjectWrapper(false).readOnlyProperty.asPrimitive().value)
    }

    @Test
    fun double() {
        assertEquals(0.0, propertyOf(0.0).asPrimitive().value)
        assertEquals(0.0, ReadOnlyObjectWrapper(0.0).readOnlyProperty.asPrimitive().value)
    }

    @Test
    fun float() {
        assertEquals(0f, propertyOf(0f).asPrimitive().value)
        assertEquals(0f, ReadOnlyObjectWrapper(0f).readOnlyProperty.asPrimitive().value)
    }

    @Test
    fun int() {
        assertEquals(0, propertyOf(0).asPrimitive().value)
        assertEquals(0, ReadOnlyObjectWrapper(0).readOnlyProperty.asPrimitive().value)
    }

    @Test
    fun long() {
        assertEquals(0L, propertyOf(0L).asPrimitive().value)
        assertEquals(0L, ReadOnlyObjectWrapper(0L).readOnlyProperty.asPrimitive().value)
    }
}


<|start_filename|>ktfx-commons/tests/src/ktfx/collections/ObservableArraysIntTest.kt<|end_filename|>
package ktfx.collections

import javafx.collections.ObservableIntegerArray
import com.hendraanggrian.ktfx.test.BaseArraysTest

class ObservableArraysIntTest : BaseArraysTest<ObservableIntegerArray, IntArray, Int>() {

    override val typedArray = arrayOf(1, 2, 3)
    override val primitiveArray = intArrayOf(1, 2, 3)

    override fun of() = observableIntArrayOf()
    override fun of(values: Array<Int>) = observableIntArrayOf(*values.toIntArray())

    override fun IntArray.to() = toObservableArray()
}


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_Menu.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.Event
import javafx.scene.control.Menu
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Menu.setOnShowing
 */
public inline fun Menu.onShowing(noinline action: (Event) -> Unit) {
    return setOnShowing(action)
}

/**
 * @see Menu.setOnShown
 */
public inline fun Menu.onShown(noinline action: (Event) -> Unit) {
    return setOnShown(action)
}

/**
 * @see Menu.setOnHiding
 */
public inline fun Menu.onHiding(noinline action: (Event) -> Unit) {
    return setOnHiding(action)
}

/**
 * @see Menu.setOnHidden
 */
public inline fun Menu.onHidden(noinline action: (Event) -> Unit) {
    return setOnHidden(action)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/chart/BarChartTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.chart.BarChart
import javafx.scene.chart.CategoryAxis
import javafx.scene.chart.NumberAxis
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class BarChartTest : LayoutsTest<KtfxPane, BarChart<String, Number>>() {
    private lateinit var axis1: CategoryAxis
    private lateinit var axis2: NumberAxis

    override fun onCreate() {
        super.onCreate()
        axis1 = CategoryAxis()
        axis2 = NumberAxis(1.0, 2.0, 3.0)
    }

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = barChart(axis1, axis2) { }
    override fun KtfxPane.child2() = barChart(axis1, axis2)
    override fun KtfxPane.child3() = barChart(axis1, axis2) { }

    override fun BarChart<String, Number>.testDefaultValues() {
        assertEquals(axis1, xAxis)
        assertEquals(axis2, yAxis)
        assertThat(data).isEmpty()
        assertEquals(10.0, categoryGap)
    }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/DialogTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.control.Dialog
import javafx.scene.control.DialogEvent
import com.hendraanggrian.ktfx.test.BaseDialogTest
import kotlin.test.Ignore

@Ignore
class DialogTest : BaseDialogTest() {

    override fun <E> Dialog<E>.callOnCloseRequest(action: (DialogEvent) -> Unit) = onCloseRequest(action)
    override fun <E> Dialog<E>.callOnShowing(action: (DialogEvent) -> Unit) = onShowing(action)
    override fun <E> Dialog<E>.callOnShown(action: (DialogEvent) -> Unit) = onShown(action)
    override fun <E> Dialog<E>.callOnHiding(action: (DialogEvent) -> Unit) = onHiding(action)
    override fun <E> Dialog<E>.callOnHidden(action: (DialogEvent) -> Unit) = onHidden(action)
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXTextAreaTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTextArea
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class JFXTextAreaTest : LayoutsTest<KtfxPane, JFXTextArea>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxTextArea { }
    override fun KtfxPane.child2() = jfxTextArea()
    override fun KtfxPane.child3() = jfxTextArea { }

    override fun JFXTextArea.testDefaultValues() {
        assertNull(text)
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/src/com/jfoenix/controls/KtfxJFXRippler.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXRippler
import javafx.scene.Node
import ktfx.layouts.NodeManager
import kotlin.contracts.ExperimentalContracts

/**
 * [JFXRippler] with dynamic-layout dsl support.
 * Invoking dsl will only set its children.
 */
open class KtfxJFXRippler : JFXRippler(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { control = it }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ColorPickerTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.ColorPicker
import javafx.scene.paint.Color
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class ColorPickerTest : LayoutsTest<KtfxPane, ColorPicker>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = colorPicker { }
    override fun KtfxPane.child2() = colorPicker()
    override fun KtfxPane.child3() = colorPicker { }

    override fun ColorPicker.testDefaultValues() {
        assertEquals(Color.WHITE, value)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/SliderTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.Slider
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class SliderTest : LayoutsTest<KtfxPane, Slider>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = slider { }
    override fun KtfxPane.child2() = slider()
    override fun KtfxPane.child3() = slider { }

    override fun Slider.testDefaultValues() {
        assertEquals(0.0, min)
        assertEquals(100.0, max)
        assertEquals(0.0, value)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/NumberValueBindingDouble.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("NumberValueBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.DoubleBinding
import javafx.beans.binding.DoubleExpression
import javafx.beans.value.ObservableDoubleValue
import javafx.beans.value.ObservableNumberValue

/** @see DoubleExpression.negate */
inline operator fun ObservableDoubleValue.unaryMinus(): DoubleBinding = Bindings.negate(this) as DoubleBinding

/** @see DoubleExpression.add */
inline operator fun ObservableDoubleValue.plus(other: ObservableNumberValue): DoubleBinding =
    Bindings.add(this, other) as DoubleBinding

/** @see DoubleExpression.add */
inline operator fun ObservableDoubleValue.plus(other: Double): DoubleBinding = Bindings.add(this, other)

/** @see DoubleExpression.add */
inline operator fun Double.plus(other: ObservableDoubleValue): DoubleBinding = Bindings.add(this, other)

/** @see DoubleExpression.add */
inline operator fun ObservableDoubleValue.plus(other: Float): DoubleBinding = Bindings.add(this, other) as DoubleBinding

/** @see DoubleExpression.add */
inline operator fun Float.plus(other: ObservableDoubleValue): DoubleBinding = Bindings.add(this, other) as DoubleBinding

/** @see DoubleExpression.add */
inline operator fun ObservableDoubleValue.plus(other: Long): DoubleBinding = Bindings.add(this, other) as DoubleBinding

/** @see DoubleExpression.add */
inline operator fun Long.plus(other: ObservableDoubleValue): DoubleBinding = Bindings.add(this, other) as DoubleBinding

/** @see DoubleExpression.add */
inline operator fun ObservableDoubleValue.plus(other: Int): DoubleBinding = Bindings.add(this, other) as DoubleBinding

/** @see DoubleExpression.add */
inline operator fun Int.plus(other: ObservableDoubleValue): DoubleBinding = Bindings.add(this, other) as DoubleBinding

/** @see DoubleExpression.subtract */
inline operator fun ObservableDoubleValue.minus(other: ObservableDoubleValue): DoubleBinding =
    Bindings.subtract(this, other) as DoubleBinding

/** @see DoubleExpression.subtract */
inline operator fun ObservableDoubleValue.minus(other: Double): DoubleBinding = Bindings.subtract(this, other)

/** @see DoubleExpression.subtract */
inline operator fun Double.minus(other: ObservableDoubleValue): DoubleBinding = Bindings.subtract(this, other)

/** @see DoubleExpression.subtract */
inline operator fun ObservableDoubleValue.minus(other: Float): DoubleBinding =
    Bindings.subtract(this, other) as DoubleBinding

/** @see DoubleExpression.subtract */
inline operator fun Float.minus(other: ObservableDoubleValue): DoubleBinding =
    Bindings.subtract(this, other) as DoubleBinding

/** @see DoubleExpression.subtract */
inline operator fun ObservableDoubleValue.minus(other: Long): DoubleBinding =
    Bindings.subtract(this, other) as DoubleBinding

/** @see DoubleExpression.subtract */
inline operator fun Long.minus(other: ObservableDoubleValue): DoubleBinding =
    Bindings.subtract(this, other) as DoubleBinding

/** @see DoubleExpression.subtract */
inline operator fun ObservableDoubleValue.minus(other: Int): DoubleBinding =
    Bindings.subtract(this, other) as DoubleBinding

/** @see DoubleExpression.subtract */
inline operator fun Int.minus(other: ObservableDoubleValue): DoubleBinding =
    Bindings.subtract(this, other) as DoubleBinding

/** @see DoubleExpression.multiply */
inline operator fun ObservableDoubleValue.times(other: ObservableDoubleValue): DoubleBinding =
    Bindings.multiply(this, other) as DoubleBinding

/** @see DoubleExpression.multiply */
inline operator fun ObservableDoubleValue.times(other: Double): DoubleBinding = Bindings.multiply(this, other)

/** @see DoubleExpression.multiply */
inline operator fun Double.times(other: ObservableDoubleValue): DoubleBinding = Bindings.multiply(this, other)

/** @see DoubleExpression.multiply */
inline operator fun ObservableDoubleValue.times(other: Float): DoubleBinding =
    Bindings.multiply(this, other) as DoubleBinding

/** @see DoubleExpression.multiply */
inline operator fun Float.times(other: ObservableDoubleValue): DoubleBinding =
    Bindings.multiply(this, other) as DoubleBinding

/** @see DoubleExpression.multiply */
inline operator fun ObservableDoubleValue.times(other: Long): DoubleBinding =
    Bindings.multiply(this, other) as DoubleBinding

/** @see DoubleExpression.multiply */
inline operator fun Long.times(other: ObservableDoubleValue): DoubleBinding =
    Bindings.multiply(this, other) as DoubleBinding

/** @see DoubleExpression.multiply */
inline operator fun ObservableDoubleValue.times(other: Int): DoubleBinding =
    Bindings.multiply(this, other) as DoubleBinding

/** @see DoubleExpression.multiply */
inline operator fun Int.times(other: ObservableDoubleValue): DoubleBinding =
    Bindings.multiply(this, other) as DoubleBinding

/** @see DoubleExpression.divide */
inline operator fun ObservableDoubleValue.div(other: ObservableDoubleValue): DoubleBinding =
    Bindings.divide(this, other) as DoubleBinding

/** @see DoubleExpression.divide */
inline operator fun ObservableDoubleValue.div(other: Double): DoubleBinding = Bindings.divide(this, other)

/** @see DoubleExpression.divide */
inline operator fun Double.div(other: ObservableDoubleValue): DoubleBinding = Bindings.divide(this, other)

/** @see DoubleExpression.divide */
inline operator fun ObservableDoubleValue.div(other: Float): DoubleBinding =
    Bindings.divide(this, other) as DoubleBinding

/** @see DoubleExpression.divide */
inline operator fun Float.div(other: ObservableDoubleValue): DoubleBinding =
    Bindings.divide(this, other) as DoubleBinding

/** @see DoubleExpression.divide */
inline operator fun ObservableDoubleValue.div(other: Long): DoubleBinding =
    Bindings.divide(this, other) as DoubleBinding

/** @see DoubleExpression.divide */
inline operator fun Long.div(other: ObservableDoubleValue): DoubleBinding =
    Bindings.divide(this, other) as DoubleBinding

/** @see DoubleExpression.divide */
inline operator fun ObservableDoubleValue.div(other: Int): DoubleBinding = Bindings.divide(this, other) as DoubleBinding

/** @see DoubleExpression.divide */
inline operator fun Int.div(other: ObservableDoubleValue): DoubleBinding = Bindings.divide(this, other) as DoubleBinding


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_PopupWindow.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.event.Event
import javafx.stage.PopupWindow
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see PopupWindow.setOnAutoHide
 */
public fun PopupWindow.onAutoHide(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnAutoHide { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-coroutines/src/javafx/collections/ObservableSet.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxCoroutinesKt")

package ktfx.coroutines

import javafx.collections.ObservableSet
import javafx.collections.SetChangeListener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

/** Add a listener to this observable map. */
fun <E> ObservableSet<E>.listener(
    context: CoroutineContext = Dispatchers.JavaFx,
    listener: suspend CoroutineScope.(SetChangeListener.Change<out E>) -> Unit
): SetChangeListener<E> = SetChangeListener<E> { change ->
    GlobalScope.launch(context) { listener(change) }
}.also { addListener(it) }


<|start_filename|>ktfx-commons/src/ktfx/PropertiesCreate.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("PropertiesKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx

import javafx.beans.property.BooleanProperty
import javafx.beans.property.DoubleProperty
import javafx.beans.property.FloatProperty
import javafx.beans.property.IntegerProperty
import javafx.beans.property.ListProperty
import javafx.beans.property.LongProperty
import javafx.beans.property.MapProperty
import javafx.beans.property.ObjectProperty
import javafx.beans.property.Property
import javafx.beans.property.SetProperty
import javafx.beans.property.SimpleBooleanProperty
import javafx.beans.property.SimpleDoubleProperty
import javafx.beans.property.SimpleFloatProperty
import javafx.beans.property.SimpleIntegerProperty
import javafx.beans.property.SimpleListProperty
import javafx.beans.property.SimpleLongProperty
import javafx.beans.property.SimpleMapProperty
import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleSetProperty
import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty
import javafx.collections.ObservableList
import javafx.collections.ObservableMap
import javafx.collections.ObservableSet

/** Create a [Property] with [initialValue]. */
inline fun <T> propertyOf(initialValue: T? = null): ObjectProperty<T> = SimpleObjectProperty<T>(initialValue)

/** Create a [StringProperty] with [initialValue]. */
inline fun stringPropertyOf(initialValue: String? = null): StringProperty = SimpleStringProperty(initialValue)

/** Create a [BooleanProperty] with [initialValue]. */
inline fun booleanPropertyOf(initialValue: Boolean = false): BooleanProperty = SimpleBooleanProperty(initialValue)

/** Create a [DoubleProperty] with [initialValue]. */
inline fun doublePropertyOf(initialValue: Double = 0.0): DoubleProperty = SimpleDoubleProperty(initialValue)

/** Create a [FloatProperty] with [initialValue]. */
inline fun floatPropertyOf(initialValue: Float = 0f): FloatProperty = SimpleFloatProperty(initialValue)

/** Create a [LongProperty] with [initialValue]. */
inline fun longPropertyOf(initialValue: Long = 0L): LongProperty = SimpleLongProperty(initialValue)

/** Create a [IntegerProperty] with [initialValue]. */
inline fun intPropertyOf(initialValue: Int = 0): IntegerProperty = SimpleIntegerProperty(initialValue)

/** Create a [ListProperty] with [initialValue]. */
inline fun <E> listPropertyOf(initialValue: ObservableList<E>? = null): ListProperty<E> =
    SimpleListProperty<E>(initialValue)

/** Create a [SetProperty] with [initialValue]. */
inline fun <E> setPropertyOf(initialValue: ObservableSet<E>? = null): SetProperty<E> =
    SimpleSetProperty<E>(initialValue)

/** Create a [MapProperty] with [initialValue]. */
inline fun <K, V> mapPropertyOf(initialValue: ObservableMap<K, V>? = null): MapProperty<K, V> =
    SimpleMapProperty<K, V>(initialValue)


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_Node.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.Node
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Node.setOnDragEntered
 */
public fun Node.onDragEntered(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DragEvent) -> Unit
) {
    return setOnDragEntered { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnDragExited
 */
public fun Node.onDragExited(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DragEvent) -> Unit
) {
    return setOnDragExited { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnDragOver
 */
public fun Node.onDragOver(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DragEvent) -> Unit
) {
    return setOnDragOver { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnDragDropped
 */
public fun Node.onDragDropped(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DragEvent) -> Unit
) {
    return setOnDragDropped { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnDragDone
 */
public fun Node.onDragDone(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DragEvent) -> Unit
) {
    return setOnDragDone { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnContextMenuRequested
 */
public fun Node.onContextMenuRequested(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ContextMenuEvent) -> Unit
) {
    return setOnContextMenuRequested { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMouseClicked
 */
public fun Node.onMouseClicked(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseClicked { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMouseDragged
 */
public fun Node.onMouseDragged(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseDragged { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMouseEntered
 */
public fun Node.onMouseEntered(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseEntered { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMouseExited
 */
public fun Node.onMouseExited(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseExited { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMouseMoved
 */
public fun Node.onMouseMoved(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseMoved { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMousePressed
 */
public fun Node.onMousePressed(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMousePressed { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMouseReleased
 */
public fun Node.onMouseReleased(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseReleased { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnDragDetected
 */
public fun Node.onDragDetected(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnDragDetected { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMouseDragOver
 */
public fun Node.onMouseDragOver(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseDragEvent) -> Unit
) {
    return setOnMouseDragOver { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMouseDragReleased
 */
public fun Node.onMouseDragReleased(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseDragEvent) -> Unit
) {
    return setOnMouseDragReleased { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMouseDragEntered
 */
public fun Node.onMouseDragEntered(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseDragEvent) -> Unit
) {
    return setOnMouseDragEntered { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnMouseDragExited
 */
public fun Node.onMouseDragExited(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseDragEvent) -> Unit
) {
    return setOnMouseDragExited { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnScrollStarted
 */
public fun Node.onScrollStarted(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ScrollEvent) -> Unit
) {
    return setOnScrollStarted { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnScroll
 */
public fun Node.onScroll(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ScrollEvent) -> Unit
) {
    return setOnScroll { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnScrollFinished
 */
public fun Node.onScrollFinished(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ScrollEvent) -> Unit
) {
    return setOnScrollFinished { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnRotationStarted
 */
public fun Node.onRotationStarted(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(RotateEvent) -> Unit
) {
    return setOnRotationStarted { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnRotate
 */
public fun Node.onRotate(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(RotateEvent) -> Unit
) {
    return setOnRotate { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnRotationFinished
 */
public fun Node.onRotationFinished(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(RotateEvent) -> Unit
) {
    return setOnRotationFinished { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnZoomStarted
 */
public fun Node.onZoomStarted(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ZoomEvent) -> Unit
) {
    return setOnZoomStarted { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnZoom
 */
public fun Node.onZoom(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ZoomEvent) -> Unit
) {
    return setOnZoom { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnZoomFinished
 */
public fun Node.onZoomFinished(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ZoomEvent) -> Unit
) {
    return setOnZoomFinished { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnSwipeUp
 */
public fun Node.onSwipeUp(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(SwipeEvent) -> Unit
) {
    return setOnSwipeUp { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnSwipeDown
 */
public fun Node.onSwipeDown(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(SwipeEvent) -> Unit
) {
    return setOnSwipeDown { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnSwipeLeft
 */
public fun Node.onSwipeLeft(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(SwipeEvent) -> Unit
) {
    return setOnSwipeLeft { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnSwipeRight
 */
public fun Node.onSwipeRight(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(SwipeEvent) -> Unit
) {
    return setOnSwipeRight { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnTouchPressed
 */
public fun Node.onTouchPressed(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(TouchEvent) -> Unit
) {
    return setOnTouchPressed { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnTouchMoved
 */
public fun Node.onTouchMoved(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(TouchEvent) -> Unit
) {
    return setOnTouchMoved { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnTouchReleased
 */
public fun Node.onTouchReleased(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(TouchEvent) -> Unit
) {
    return setOnTouchReleased { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnTouchStationary
 */
public fun Node.onTouchStationary(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(TouchEvent) -> Unit
) {
    return setOnTouchStationary { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnKeyPressed
 */
public fun Node.onKeyPressed(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(KeyEvent) -> Unit
) {
    return setOnKeyPressed { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnKeyReleased
 */
public fun Node.onKeyReleased(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(KeyEvent) -> Unit
) {
    return setOnKeyReleased { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnKeyTyped
 */
public fun Node.onKeyTyped(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(KeyEvent) -> Unit
) {
    return setOnKeyTyped { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Node.setOnInputMethodTextChanged
 */
public fun Node.onInputMethodTextChanged(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(InputMethodEvent) -> Unit
) {
    return setOnInputMethodTextChanged { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/concurrent/TaskTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.concurrent.Task
import javafx.concurrent.WorkerStateEvent
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseTaskTest

class TaskTest : BaseTaskTest() {

    override fun <E> Task<E>.callOnScheduled(action: (WorkerStateEvent) -> Unit) =
        onScheduled(Dispatchers.Unconfined) { action(it) }

    override fun <E> Task<E>.callOnRunning(action: (WorkerStateEvent) -> Unit) =
        onRunning(Dispatchers.Unconfined) { action(it) }

    override fun <E> Task<E>.callOnSucceeded(action: (WorkerStateEvent) -> Unit) =
        onSucceeded(Dispatchers.Unconfined) { action(it) }

    override fun <E> Task<E>.callOnCancelled(action: (WorkerStateEvent) -> Unit) =
        onCancelled(Dispatchers.Unconfined) { action(it) }

    override fun <E> Task<E>.callOnFailed(action: (WorkerStateEvent) -> Unit) =
        onFailed(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/ArraysBindingInteger.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ArraysBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.IntegerBinding
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableNumberValue
import javafx.collections.ObservableIntegerArray

/** Creates a new [IntegerBinding] that contains the element of an [ObservableIntegerArray] at the specified position. */
inline fun ObservableIntegerArray.getBinding(index: Int): IntegerBinding =
    Bindings.integerValueAt(this, index)

/** Creates a new [IntegerBinding] that contains the element of an [ObservableIntegerArray] at the specified position. */
inline fun ObservableIntegerArray.getBinding(index: ObservableNumberValue): IntegerBinding =
    Bindings.integerValueAt(this, index)

/** Creates a new [IntegerBinding] that contains the element of an [ObservableIntegerArray] at the specified position. */
inline fun ObservableIntegerArray.getBinding(index: ObservableIntegerValue): IntegerBinding =
    Bindings.integerValueAt(this, index)

/**
 * Performs the given [action] on each element binding.
 * @see forEach
 */
inline fun ObservableIntegerArray.forEachBinding(action: (IntegerBinding) -> Unit) {
    for (index in 0 until size()) {
        action(Bindings.integerValueAt(this, index))
    }
}

/**
 * Performs the given [action] on each element binding, accompanied with the index of the element.
 * @see forEachIndexed
 */
inline fun ObservableIntegerArray.forEachBindingIndexed(action: (index: Int, IntegerBinding) -> Unit) {
    for (index in 0 until size()) {
        action(index, Bindings.integerValueAt(this, index))
    }
}


<|start_filename|>thirdparty/controlsfx-listeners/src/ktfx/controlsfx/listeners/_HyperlinkLabel.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.listeners

import javafx.event.ActionEvent
import org.controlsfx.control.HyperlinkLabel
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see HyperlinkLabel.setOnAction
 */
public inline fun HyperlinkLabel.onAction(noinline action: (ActionEvent) -> Unit) {
    return setOnAction(action)
}


<|start_filename|>testing/listeners-coroutines/src/com/hendraanggrian/ktfx/test/events/FakeTouchEvent.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import com.google.common.truth.Truth.assertThat
import javafx.event.EventType
import javafx.scene.input.TouchEvent
import javafx.scene.input.TouchPoint
import kotlin.test.assertEquals
import kotlin.test.assertFalse

private val touchPoint = TouchPoint(
    0, TouchPoint.State.MOVED, 0.0, 0.0, 0.0,
    0.0, FakeEventTarget, FakePickResult
)

/**
 * @receiver source of this fake event.
 */
fun Any.assertFakeTouchEvent(actual: TouchEvent, expectedType: EventType<TouchEvent>) {
    assertEquals(this, actual.source)
    assertEquals(FakeEventTarget, actual.target)
    assertEquals(expectedType, actual.eventType)
    assertEquals(touchPoint, actual.touchPoint)
    assertThat(actual.touchPoints).isEmpty()
    assertEquals(0, actual.eventSetId)
    assertFalse(actual.isShiftDown)
    assertFalse(actual.isControlDown)
    assertFalse(actual.isAltDown)
    assertFalse(actual.isMetaDown)
}

/**
 * @receiver source of this fake event.
 */
fun Any.fakeTouchEventOf(eventType: EventType<TouchEvent>) = TouchEvent(
    this, FakeEventTarget, eventType,
    touchPoint, listOf<TouchPoint>(), 0,
    false, false, false,
    false
)

<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_ContextMenu.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.event.ActionEvent
import javafx.scene.control.ContextMenu
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see ContextMenu.setOnAction
 */
public fun ContextMenu.onAction(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ActionEvent) -> Unit
) {
    return setOnAction { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_TableColumn.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.control.TableColumn
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see TableColumn.setOnEditStart
 */
public inline fun <S, T> TableColumn<S, T>.onEditStart(
    noinline
    action: (TableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditStart(action)
}

/**
 * @see TableColumn.setOnEditCommit
 */
public inline fun <S, T> TableColumn<S, T>.onEditCommit(
    noinline
    action: (TableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditCommit(action)
}

/**
 * @see TableColumn.setOnEditCancel
 */
public inline fun <S, T> TableColumn<S, T>.onEditCancel(
    noinline
    action: (TableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditCancel(action)
}


<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_CustomTextField.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.textfield.CustomTextField
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [CustomTextField] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.customTextField(): CustomTextField = customTextField() { }

/**
 * Create a [CustomTextField] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun customTextField(configuration: (@KtfxLayoutDslMarker CustomTextField).() -> Unit):
    CustomTextField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomTextField()
    child.configuration()
    return child
}

/**
 * Add a [CustomTextField] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.customTextField(
    configuration: (
        @KtfxLayoutDslMarker
        CustomTextField
    ).() -> Unit
): CustomTextField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomTextField()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [CustomTextField].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledCustomTextField(vararg styleClass: String, id: String? = null): CustomTextField =
    styledCustomTextField(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [CustomTextField] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledCustomTextField(vararg styleClass: String, id: String? = null):
    CustomTextField = styledCustomTextField(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [CustomTextField] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledCustomTextField(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker CustomTextField).() -> Unit
): CustomTextField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomTextField()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [CustomTextField] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledCustomTextField(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker CustomTextField).() -> Unit
): CustomTextField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomTextField()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>testing/commons/src/com/hendraanggrian/ktfx/test/SampleImage.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.image.Image

class SampleImage : Image("/sample.png")

<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/BindingsObjectTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.booleanPropertyOf
import ktfx.doublePropertyOf
import ktfx.floatPropertyOf
import ktfx.intPropertyOf
import ktfx.longPropertyOf
import ktfx.propertyOf
import ktfx.time.minutes
import ktfx.time.plus
import ktfx.time.seconds
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class BindingsObjectTest {

    @Test
    fun nullability() {
        val dependency = propertyOf<String>()
        val binding = bindingOf<String>(dependency) { null }
        assertNull(binding.get())
    }

    @Test
    fun multipleDependencies() {
        val dependency1 = propertyOf(1.minutes)
        val dependency2 = propertyOf(30.seconds)
        val binding1 = bindingOf(dependency1, dependency2) { dependency1.value + dependency2.value }
        assertEquals(90.seconds, binding1.value)
        dependency1.value = 15.seconds
        assertEquals(45.seconds, binding1.value)

        val dependency3 = propertyOf(1.minutes)
        val dependency4 = propertyOf(30.seconds)
        val binding2 = bindingOf(listOf(dependency3, dependency4)) { dependency3.value + dependency4.value }
        assertEquals(90.seconds, binding2.value)
        dependency3.value = 15.seconds
        assertEquals(45.seconds, binding2.value)
    }

    @Test
    fun anyDependency() {
        val dependency = propertyOf(1.minutes)
        val binding = dependency.asAny { it }
        assertEquals(60.seconds, binding.value)
        dependency.value = null
        assertNull(binding.value)
    }

    @Test
    fun booleanDependency() {
        val dependency = booleanPropertyOf()
        val binding = dependency.asAny { if (it) 1.seconds else 2.seconds }
        assertEquals(2.seconds, binding.value)
        dependency.value = true
        assertEquals(1.seconds, binding.value)
    }

    @Test
    fun doubleDependency() {
        val dependency = doublePropertyOf()
        val binding = dependency.asAny { it.seconds }
        assertEquals(0.seconds, binding.value)
        dependency.value = Double.MAX_VALUE
        assertEquals(Double.MAX_VALUE.seconds, binding.value)
    }

    @Test
    fun floatDependency() {
        val dependency = floatPropertyOf()
        val binding = dependency.asAny { it.toDouble().seconds }
        assertEquals(0.seconds, binding.value)
        dependency.value = Float.MAX_VALUE
        assertEquals(Float.MAX_VALUE.toDouble().seconds, binding.value)
    }

    @Test
    fun intDependency() {
        val dependency = intPropertyOf()
        val binding = dependency.asAny { it.seconds }
        assertEquals(0.seconds, binding.value)
        dependency.value = Int.MAX_VALUE
        assertEquals(Int.MAX_VALUE.seconds, binding.value)
    }

    @Test
    fun longDependency() {
        val dependency = longPropertyOf()
        val binding = dependency.asAny { it.seconds }
        assertEquals(0.seconds, binding.value)
        dependency.value = Long.MAX_VALUE
        assertEquals(Long.MAX_VALUE.seconds, binding.value)
    }
}


<|start_filename|>thirdparty/jfoenix-layouts/src/com/jfoenix/controls/KtfxJFXDrawer.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXDrawer
import javafx.scene.Node
import ktfx.layouts.NodeManager
import kotlin.contracts.ExperimentalContracts

/**
 * [JFXDrawer] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxJFXDrawer : JFXDrawer(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { content += it }
}


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/listeners/JFoenix.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.listeners

import com.hendraanggrian.kotlinpoet.parameterizedBy
import com.jfoenix.controls.JFXAutoCompletePopup
import com.jfoenix.controls.JFXDecorator
import com.jfoenix.controls.JFXDialog
import com.jfoenix.controls.JFXDrawer
import com.jfoenix.controls.events.JFXAutoCompleteEvent
import com.jfoenix.controls.events.JFXDialogEvent
import com.jfoenix.controls.events.JFXDrawerEvent
import com.jfoenix.transitions.JFXAnimationTimer
import com.hendraanggrian.ktfx.codegen.T

val ListenersFactory.Companion.JFoenix: ListenersFactory
    get() = ListenersFactory(
        "thirdparty/jfoenix-listeners/src",
        "ktfx.jfoenix.listeners",
        "JFoenixListenersKt",
    ).apply { initJFoenix() }

val CoroutinesFactory.Companion.JFoenix: CoroutinesFactory
    get() = CoroutinesFactory(
        "thirdparty/jfoenix-coroutines/src",
        "ktfx.jfoenix.coroutines",
        "JFoenixCoroutinesKt",
    ).apply { initJFoenix() }

fun BaseListenersFactory.initJFoenix() {
    // com.jfoenix.controls
    (JFXAutoCompletePopup::class.parameterizedBy(T)) {
        "setSelectionHandler" { action(JFXAutoCompleteEvent::class.parameterizedBy(T)) }
    }
    JFXDecorator::class { "setOnCloseButtonAction" { action(*emptyArray()) } }
    JFXDialog::class {
        "setOnDialogClosed" { action<JFXDialogEvent>() }
        "setOnDialogOpened" { action<JFXDialogEvent>() }
    }
    JFXDrawer::class {
        "setOnDrawerClosed" { action<JFXDrawerEvent>() }
        "setOnDrawerClosing" { action<JFXDrawerEvent>() }
        "setOnDrawerOpened" { action<JFXDrawerEvent>() }
        "setOnDrawerOpening" { action<JFXDrawerEvent>() }
    }
    // com.jfoenix.transitions
    JFXAnimationTimer::class { "setOnFinished" { action(*emptyArray()) } }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_ListView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.collections.FXCollections.observableArrayList
import javafx.collections.ObservableList
import javafx.scene.control.ListView
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [ListView] to this manager.
 *
 * @return the control added.
 */
public fun <T> NodeManager.listView(items: ObservableList<T> = observableArrayList()): ListView<T> =
    listView(items = items) { }

/**
 * Create a [ListView] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun <T> listView(
    items: ObservableList<T> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker ListView<T>).() -> Unit
): ListView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ListView<T>(items)
    child.configuration()
    return child
}

/**
 * Add a [ListView] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun <T> NodeManager.listView(
    items: ObservableList<T> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker ListView<T>).() -> Unit
): ListView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ListView<T>(items)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [ListView].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun <T> styledListView(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): ListView<T> = styledListView(items = items, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [ListView] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun <T> NodeManager.styledListView(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): ListView<T> = styledListView(items = items, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [ListView] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun <T> styledListView(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker ListView<T>).() -> Unit
): ListView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ListView<T>(items)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [ListView] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun <T> NodeManager.styledListView(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker ListView<T>).() -> Unit
): ListView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ListView<T>(items)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/src/javafx/scene/SubScene.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.SubScene
import javafx.scene.layout.Pane
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/** Create a [SubScene] with configuration block. */
inline fun subScene(
    width: Double = -1.0,
    height: Double = -1.0,
    configuration: (@KtfxLayoutDslMarker KtfxSubScene).() -> Unit
): SubScene {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return KtfxSubScene(Pane(), width, height).apply(configuration)
}


<|start_filename|>thirdparty/jfoenix-commons/src/ktfx/jfoenix/controls/JFXNodeUtils.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.jfoenix.controls

import com.jfoenix.utils.JFXNodeUtils
import javafx.beans.InvalidationListener
import javafx.beans.value.ObservableValue
import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.scene.Node
import javafx.scene.input.MouseEvent
import javafx.scene.layout.Background
import javafx.scene.layout.Region
import javafx.scene.paint.Color
import javafx.scene.paint.Paint
import javafx.util.Duration

inline fun Region.updateBackground(
    newBackground: Background,
    paint: Paint = Color.BLACK
): Unit = JFXNodeUtils.updateBackground(newBackground, this, paint)

inline fun Color.toHex(): String = JFXNodeUtils.colorToHex(this)

inline fun Node.pressAndHoldHandler(
    holdTime: Duration,
    noinline handler: (MouseEvent) -> Unit
): Unit = JFXNodeUtils.addPressAndHoldHandler(this, holdTime, handler)

inline fun Node.pressAndHoldFilter(
    holdTime: Duration,
    noinline handler: (MouseEvent) -> Unit
): Unit = JFXNodeUtils.addPressAndHoldFilter(this, holdTime, handler)

inline fun <T> ObservableValue<T>.delayedPropertyInvalidationListener(
    delayTime: Duration,
    noinline consumer: (T) -> Unit
): InvalidationListener = JFXNodeUtils.addDelayedPropertyInvalidationListener(this, delayTime, consumer)

inline fun <T> ObservableValue<T>.delayedPropertyInvalidationListener(
    delayTime: Duration,
    noinline justInTimeConsumer: (T) -> Unit,
    noinline consumer: (T) -> Unit
): InvalidationListener =
    JFXNodeUtils.addDelayedPropertyInvalidationListener(this, delayTime, justInTimeConsumer, consumer)

inline fun <T : Event> Node.delayedEventHandler(
    delayTime: Duration,
    eventType: EventType<T>,
    noinline handler: (T) -> Unit
): EventHandler<in T> = JFXNodeUtils.addDelayedEventHandler(this, delayTime, eventType, handler)


<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/TableViewTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.TableColumn
import javafx.scene.control.TableView
import com.hendraanggrian.ktfx.test.BaseTableViewTest

class TableViewTest : BaseTableViewTest() {

    override fun <S> TableView<S>.callOnSort(action: (SortEvent<TableView<S>>) -> Unit) = onSort(action)
    override fun <S> TableView<S>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit) = onScrollTo(action)
    override fun <S> TableView<S>.callOnScrollToColumn(action: (ScrollToEvent<TableColumn<S, *>>) -> Unit) =
        onScrollToColumn(action)
}

<|start_filename|>thirdparty/jfoenix-commons/src/ktfx/jfoenix/controls/JFXTableColumns.kt<|end_filename|>
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.controls

import com.jfoenix.controls.JFXTreeTableColumn
import com.jfoenix.controls.JFXTreeTableView
import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject
import javafx.scene.control.TreeTableColumn
import ktfx.controls.TableColumnDslMarker
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
 * Configure [JFXTreeTableView] columns.
 * @param configuration the configuration block.
 */
fun <S : RecursiveTreeObject<S>> JFXTreeTableView<S>.columns(
    configuration: JFXTreeTableColumnScope<S>.() -> Unit
) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    val columns2 = columns // explicit ref to avoid ambiguous label
    object : JFXTreeTableColumnScope<S> {
        override val columns: MutableCollection<TreeTableColumn<S, *>> get() = columns2
    }.configuration()
}

/**
 * Configure [JFXTreeTableColumn] columns, essentially enabling multi-line column.
 * @param configuration the configuration block.
 */
fun <S : RecursiveTreeObject<S>> JFXTreeTableColumn<S, *>.columns(
    configuration: JFXTreeTableColumnScope<S>.() -> Unit
) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    val columns2 = columns // explicit ref to avoid ambiguous label
    object : JFXTreeTableColumnScope<S> {
        override val columns: MutableCollection<TreeTableColumn<S, *>> get() = columns2
    }.configuration()
}

/** Container of [JFXTreeTableColumn], providing sets of useful operation. */
@TableColumnDslMarker
interface JFXTreeTableColumnScope<S : RecursiveTreeObject<S>> {

    /** Collection of columns within this scope. */
    val columns: MutableCollection<TreeTableColumn<S, *>>

    /** Add a default column using [text], returning the column added. */
    fun <T> column(
        text: String? = null
    ): JFXTreeTableColumn<S, T> = JFXTreeTableColumn<S, T>(text).also { columns += it }

    /** Add a column using [text] and [configuration] block, returning the column added. */
    fun <T> column(
        text: String? = null,
        configuration: JFXTreeTableColumn<S, T>.() -> Unit
    ): JFXTreeTableColumn<S, T> {
        val column = JFXTreeTableColumn<S, T>(text).apply(configuration)
        columns += column
        return column
    }

    /** Add a column using receiver and [configuration] block, returning the column added. */
    operator fun <T> String.invoke(
        configuration: JFXTreeTableColumn<S, T>.() -> Unit
    ): JFXTreeTableColumn<S, T> = column(this, configuration)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/collections/ObservableCollectionsListTest.kt<|end_filename|>
package ktfx.collections

import javafx.collections.ObservableList
import com.hendraanggrian.ktfx.test.BaseCollectionsTest

class ObservableCollectionsListTest : BaseCollectionsTest<ObservableList<String>>() {

    override fun empty() = emptyObservableList<String>()
    override fun of() = observableListOf<String>()
    override fun of(value: String) = observableListOf(value)
    override fun of(vararg values: String) = observableListOf(*values)
    override fun mutableOf() = mutableObservableListOf<String>()
    override fun mutableOf(vararg values: String) = mutableObservableListOf(*values)

    override fun Array<String>.to() = toObservableList()
    override fun List<String>.to() = toObservableList()
    override fun Sequence<String>.to() = toObservableList()
    override fun Array<String>.toMutable() = toMutableObservableList()
    override fun List<String>.toMutable() = toMutableObservableList()
    override fun Sequence<String>.toMutable() = toMutableObservableList()
}


<|start_filename|>testing/listeners-coroutines/src/com/hendraanggrian/ktfx/test/events/FakeMouseEvent.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.EventType
import javafx.scene.input.MouseButton
import javafx.scene.input.MouseEvent
import kotlin.test.assertEquals
import kotlin.test.assertFalse

/**
 * @receiver source of this fake event.
 */
fun Any.assertFakeMouseEvent(actual: MouseEvent, expectedType: EventType<MouseEvent>) {
    assertEquals(this, actual.source)
    assertEquals(FakeEventTarget, actual.target)
    assertEquals(expectedType, actual.eventType)
    assertEquals(0.0, actual.x)
    assertEquals(0.0, actual.y)
    assertEquals(0.0, actual.sceneX)
    assertEquals(0.0, actual.sceneY)
    assertFalse(actual.isShiftDown)
    assertFalse(actual.isControlDown)
    assertFalse(actual.isAltDown)
    assertFalse(actual.isMetaDown)
    assertFalse(actual.isPrimaryButtonDown)
    assertFalse(actual.isMiddleButtonDown)
    assertFalse(actual.isSecondaryButtonDown)
    assertFalse(actual.isSynthesized)
    assertFalse(actual.isPopupTrigger)
    assertFalse(actual.isStillSincePress)
    assertEquals(FakePickResult, actual.pickResult)
}

/**
 * @receiver source of this fake event.
 */
fun Any.fakeMouseEventOf(eventType: EventType<MouseEvent>) = MouseEvent(
    this, FakeEventTarget,
    eventType,
    0.0, 0.0,
    0.0, 0.0,
    MouseButton.PRIMARY, 1,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    false,
    FakePickResult
)

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/media/MediaTest.kt<|end_filename|>
package ktfx.coroutines

import com.hendraanggrian.ktfx.test.BaseMediaTest
import javafx.scene.media.Media
import kotlinx.coroutines.Dispatchers
import kotlin.test.Ignore

@Ignore
class MediaTest : BaseMediaTest() {

    override fun Media.callOnError(action: () -> Unit) =
        onError(Dispatchers.Unconfined) { action() }
}

<|start_filename|>rulesets/basic/src/com/hendraanggrian/ktfx/rules/NotNullAssertionOperatorRule.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.pinterest.ktlint.core.Rule
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.lexer.KtTokens

/** Cannot use non-null operator `!!`, use `checkNotNull` with appropriate message instead. */
class NotNullAssertionOperatorRule : Rule("not-null-assertion-operator") {

    override fun visit(node: ASTNode, autoCorrect: Boolean, emit: (Int, String, Boolean) -> Unit) {
        if (node.elementType == KtTokens.EXCLEXCL) {
            emit(node.startOffset, "Replace `!!` with `checkNotNull` with helpful message", false)
        }
    }
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/collections/ObservableArrayTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.beans.Observable
import javafx.collections.ObservableArray
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseObservableArrayTest

class ObservableArrayTest : BaseObservableArrayTest() {

    override fun <T : ObservableArray<T>> ObservableArray<T>.callListener(action: (Observable, Boolean, Int, Int) -> Unit) {
        listener(Dispatchers.Unconfined) { observable, changed, from, to ->
            action(observable, changed, from, to)
        }
    }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Arc.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.Arc
import kotlin.Double
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add an [Arc] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.arc(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    startAngle: Double = 0.0,
    length: Double = 0.0
): Arc = arc(
    centerX = centerX, centerY = centerY, radiusX = radiusX, radiusY = radiusY,
    startAngle =
    startAngle,
    length = length
) { }

/**
 * Create an [Arc] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun arc(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    startAngle: Double = 0.0,
    length: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker Arc).() -> Unit
): Arc {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Arc(centerX, centerY, radiusX, radiusY, startAngle, length)
    child.configuration()
    return child
}

/**
 * Add an [Arc] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.arc(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    startAngle: Double = 0.0,
    length: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker Arc).() -> Unit
): Arc {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Arc(centerX, centerY, radiusX, radiusY, startAngle, length)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Arc].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledArc(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    startAngle: Double = 0.0,
    length: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): Arc = styledArc(
    centerX = centerX, centerY = centerY, radiusX = radiusX, radiusY = radiusY,
    startAngle = startAngle, length = length, styleClass = *styleClass, id = id
) { }

/**
 * Add a styled [Arc] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledArc(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    startAngle: Double = 0.0,
    length: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): Arc = styledArc(
    centerX = centerX, centerY = centerY, radiusX = radiusX, radiusY = radiusY,
    startAngle = startAngle, length = length, styleClass = *styleClass, id = id
) { }

/**
 * Create a styled [Arc] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledArc(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    startAngle: Double = 0.0,
    length: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Arc).() -> Unit
): Arc {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Arc(centerX, centerY, radiusX, radiusY, startAngle, length)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Arc] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledArc(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    startAngle: Double = 0.0,
    length: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Arc).() -> Unit
): Arc {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Arc(centerX, centerY, radiusX, radiusY, startAngle, length)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/src/ktfx/cells/TreeTableCells.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.cells

import javafx.beans.value.ObservableValue
import javafx.collections.ObservableList
import javafx.scene.control.TreeTableCell
import javafx.scene.control.TreeTableColumn
import javafx.scene.control.cell.CheckBoxTreeTableCell
import javafx.scene.control.cell.ChoiceBoxTreeTableCell
import javafx.scene.control.cell.ComboBoxTreeTableCell
import javafx.scene.control.cell.ProgressBarTreeTableCell
import javafx.scene.control.cell.TextFieldTreeTableCell
import javafx.util.StringConverter

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 */
inline fun <S> TreeTableColumn<S, Boolean>.checkBoxCellFactory(): Unit =
    setCellFactory(CheckBoxTreeTableCell.forTreeTableColumn(this))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param selectedPropertyProvider A provider that, given an object from `TreeTableColumn<S,T>`,
 *  will return an `ObservableValue<Boolean>` that represents whether the given item is selected or not.
 */
inline fun <S, T> TreeTableColumn<S, T>.checkBoxCellFactory(
    noinline selectedPropertyProvider: (Int) -> ObservableValue<Boolean>
): Unit = setCellFactory(CheckBoxTreeTableCell.forTreeTableColumn(selectedPropertyProvider))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param selectedPropertyProvider A provider that, given an object from `TreeTableColumn<S,T>`,
 *  will return an `ObservableValue<Boolean>` that represents whether the given item is selected or not.
 */
inline fun <S, T> TreeTableColumn<S, T>.checkBoxCellFactory(
    converter: StringConverter<T>,
    noinline selectedPropertyProvider: (Int) -> ObservableValue<Boolean>
): Unit = setCellFactory(CheckBoxTreeTableCell.forTreeTableColumn(selectedPropertyProvider, converter))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param showLabel In some cases, it may be desirable to show a label in
 *  the TableCell beside the [javafx.scene.control.CheckBox].
 * @param selectedPropertyProvider A provider that, given an object from `TreeTableColumn<S,T>`,
 *  will return an `ObservableValue<Boolean>` that represents whether the given item is selected or not.
 */
inline fun <S, T> TreeTableColumn<S, T>.checkBoxCellFactory(
    showLabel: Boolean,
    noinline selectedPropertyProvider: (Int) -> ObservableValue<Boolean>
): Unit = setCellFactory(CheckBoxTreeTableCell.forTreeTableColumn(selectedPropertyProvider, showLabel))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <S, T> TreeTableColumn<S, T>.choiceBoxCellFactory(
    vararg items: T
): Unit = setCellFactory(ChoiceBoxTreeTableCell.forTreeTableColumn(*items))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <S, T> TreeTableColumn<S, T>.choiceBoxCellFactory(
    converter: StringConverter<T>,
    vararg items: T
): Unit = setCellFactory(ChoiceBoxTreeTableCell.forTreeTableColumn(converter, *items))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <S, T> TreeTableColumn<S, T>.choiceBoxCellFactory(
    items: ObservableList<T>
): Unit = setCellFactory(ChoiceBoxTreeTableCell.forTreeTableColumn(items))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <S, T> TreeTableColumn<S, T>.choiceBoxCellFactory(
    converter: StringConverter<T>,
    items: ObservableList<T>
): Unit = setCellFactory(ChoiceBoxTreeTableCell.forTreeTableColumn(converter, items))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <S, T> TreeTableColumn<S, T>.comboBoxCellFactory(
    vararg items: T
): Unit = setCellFactory(ComboBoxTreeTableCell.forTreeTableColumn(*items))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <S, T> TreeTableColumn<S, T>.comboBoxCellFactory(
    converter: StringConverter<T>,
    vararg items: T
): Unit = setCellFactory(ComboBoxTreeTableCell.forTreeTableColumn(converter, *items))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <S, T> TreeTableColumn<S, T>.comboBoxCellFactory(
    items: ObservableList<T>
): Unit = setCellFactory(ComboBoxTreeTableCell.forTreeTableColumn(items))

/**
 * Sets a [CheckBoxTreeTableCell] factory for use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <S, T> TreeTableColumn<S, T>.comboBoxCellFactory(
    converter: StringConverter<T>,
    items: ObservableList<T>
): Unit = setCellFactory(ComboBoxTreeTableCell.forTreeTableColumn(converter, items))

/**
 * Sets a [ProgressBarTreeTableCell] factory for use in this [TreeTableColumn].
 */
inline fun <S> TreeTableColumn<S, Double>.progressBarCellFactory(): Unit =
    setCellFactory(ProgressBarTreeTableCell.forTreeTableColumn<S>())

/**
 * Sets a [TextFieldTreeTableCell] factory for use in this [TreeTableColumn].
 */
inline fun <S> TreeTableColumn<S, String>.textFieldCellFactory(): Unit =
    setCellFactory(TextFieldTreeTableCell.forTreeTableColumn())

/**
 * Sets a [TextFieldTreeTableCell] factory for use in this [TreeTableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 */
inline fun <S, T> TreeTableColumn<S, T>.textFieldCellFactory(
    converter: StringConverter<T>
): Unit = setCellFactory(TextFieldTreeTableCell.forTreeTableColumn(converter))

/**
 * Sets a custom cell factory to use in this [TreeTableColumn].
 * @param T The type of the elements contained within the [TreeTableColumn].
 * @param configuration custom initialization block that configures [TreeTableColumn].
 */
fun <S, T> TreeTableColumn<S, T>.cellFactory(
    configuration: KtfxTreeTableCell<S, T>.(TreeTableColumn<S, T>) -> Unit
): Unit = setCellFactory { KtfxTreeTableCell<S, T>().apply { configuration(it) } }

/** Custom [TreeTableCell] configurator class. */
class KtfxTreeTableCell<S, T> : TreeTableCell<S, T>(), KtfxCell<T> {
    private var onEditStart: (() -> Unit)? = null
    private var onEditCommit: ((T?) -> Unit)? = null
    private var onEditCancel: (() -> Unit)? = null
    private var onUpdate: ((T?, empty: Boolean) -> Unit)? = null

    override fun onEditStart(action: () -> Unit) {
        onEditStart = action
    }

    override fun startEdit() {
        super.startEdit()
        onEditStart?.invoke()
    }

    override fun onEditCommit(action: (T?) -> Unit) {
        onEditCommit = action
    }

    override fun commitEdit(newValue: T?) {
        super.commitEdit(newValue)
        onEditCommit?.invoke(newValue)
    }

    override fun onEditCancel(action: () -> Unit) {
        onEditCancel = action
    }

    override fun cancelEdit() {
        super.cancelEdit()
        onEditCancel?.invoke()
    }

    override fun onUpdate(action: (T?, empty: Boolean) -> Unit) {
        onUpdate = action
    }

    override fun updateItem(item: T?, empty: Boolean) {
        super.updateItem(item, empty)
        onUpdate?.invoke(item, empty)
    }
}


<|start_filename|>ktfx-commons/src/ktfx/dialogs/InputDialogs.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.dialogs

import javafx.scene.Node
import javafx.scene.control.TextInputDialog
import javafx.scene.image.ImageView
import java.util.Optional

/**
 * Show a text input dialog with title and graphic.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param prefill default text.
 * @param dialogAction custom dialog action.
 * @return input text
 */
fun inputDialog(
    title: String? = null,
    graphic: Node? = null,
    prefill: String = "",
    dialogAction: (TextInputDialog.() -> Unit)? = null
): Optional<String> = TextInputDialog(prefill).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    dialogAction?.invoke(dialog)
}.showAndWait()

/**
 * Show a text input dialog.
 * @param prefill default text.
 * @param dialogAction custom dialog action.
 * @return input text
 */
inline fun inputDialog(
    prefill: String = "",
    noinline dialogAction: (TextInputDialog.() -> Unit)? = null
): Optional<String> = inputDialog(null, null, prefill, dialogAction)


<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/dialogs/ExceptionDialogs.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.dialogs

import javafx.scene.Node
import javafx.scene.control.ButtonType
import javafx.scene.image.ImageView
import ktfx.dialogs.graphicIcon
import ktfx.dialogs.headerTitle
import org.controlsfx.dialog.ExceptionDialog
import java.util.Optional

/**
 * Build an exception dialog with Kotlin DSL.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param exception message to show.
 * @param dialogAction custom dialog action.
 * @return selected dialog button.
 */
fun exceptionDialog(
    title: String? = null,
    graphic: Node? = null,
    exception: Throwable,
    dialogAction: (ExceptionDialog.() -> Unit)? = null
): Optional<ButtonType> = ExceptionDialog(exception).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    dialogAction?.invoke(dialog)
}.showAndWait()

/**
 * Build an exception dialog with Kotlin DSL.
 * @param exception message to show.
 * @param dialogAction custom dialog action.
 * @return selected dialog button.
 */
inline fun exceptionDialog(
    exception: Throwable,
    noinline dialogAction: (ExceptionDialog.() -> Unit)? = null
): Optional<ButtonType> = exceptionDialog(null, null, exception, dialogAction)


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_ComboBoxBase.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.ComboBoxBase
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see ComboBoxBase.setOnAction
 */
public inline fun ComboBoxBase<*>.onAction(noinline action: (ActionEvent) -> Unit) {
    return setOnAction(action)
}

/**
 * @see ComboBoxBase.setOnShowing
 */
public inline fun ComboBoxBase<*>.onShowing(noinline action: (Event) -> Unit) {
    return setOnShowing(action)
}

/**
 * @see ComboBoxBase.setOnShown
 */
public inline fun ComboBoxBase<*>.onShown(noinline action: (Event) -> Unit) {
    return setOnShown(action)
}

/**
 * @see ComboBoxBase.setOnHiding
 */
public inline fun ComboBoxBase<*>.onHiding(noinline action: (Event) -> Unit) {
    return setOnHiding(action)
}

/**
 * @see ComboBoxBase.setOnHidden
 */
public inline fun ComboBoxBase<*>.onHidden(noinline action: (Event) -> Unit) {
    return setOnHidden(action)
}


<|start_filename|>ktfx-commons/src/ktfx/windows/Stage.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.windows

import javafx.scene.Scene
import javafx.scene.image.Image
import javafx.stage.Stage
import javafx.stage.StageStyle
import ktfx.internal.KtfxInternals.NO_GETTER
import ktfx.internal.KtfxInternals.noGetter
import kotlin.DeprecationLevel.ERROR

/** Get window as [Stage]. */
inline val Scene.stage: Stage get() = window as Stage

/** Removes old icons and set a new one to this stage. */
inline var Stage.icon: Image
    get() = icons.first()
    set(value) {
        icons.setAll(value)
    }

/** Sets minimum width and height of this [Stage]. */
var Stage.minSize: Pair<Number, Number>
    @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
    set(value) {
        minWidth = value.first.toDouble()
        minHeight = value.second.toDouble()
    }

/** Sets width and height of this [Stage]. */
var Stage.size2: Pair<Number, Number>
    @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
    set(value) {
        width = value.first.toDouble()
        height = value.second.toDouble()
    }

/** Sets maximum width and height of this [Stage]. */
var Stage.maxSize: Pair<Number, Number>
    @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
    set(value) {
        maxWidth = value.first.toDouble()
        maxHeight = value.second.toDouble()
    }

/** Creates a stage with options. */
inline fun stage(
    title: String? = null,
    icon: Image? = null,
    style: StageStyle = StageStyle.DECORATED,
    configuration: Stage.() -> Unit
): Stage = Stage(style).also {
    if (title != null) it.title = title
    if (icon != null) it.icon = icon
    it.configuration()
}

/** Creates a stage with options. */
inline fun stage(
    style: StageStyle = StageStyle.DECORATED,
    configuration: Stage.() -> Unit
): Stage = stage(null, null, style, configuration)


<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/controls/NotificationsTest.kt<|end_filename|>
package ktfx.controlsfx.controls

import com.hendraanggrian.ktfx.test.SampleImageView
import com.hendraanggrian.ktfx.test.testScene
import javafx.geometry.Pos
import javafx.scene.image.ImageView
import javafx.stage.Stage
import ktfx.time.seconds
import org.controlsfx.control.Notifications
import org.testfx.framework.junit.ApplicationTest
import kotlin.test.Test
import kotlin.test.assertNotNull

class NotificationsTest : ApplicationTest() {
    private lateinit var stage: Stage
    private lateinit var sampleGraphic: ImageView

    override fun start(stage: Stage) {
        this.stage = stage
        stage.testScene<Notifications>()
        sampleGraphic = SampleImageView()
    }

    @Test
    fun buildNotifications() {
        assertNotNull(buildNotifications {
            text = "Welcome"
            title = "Hi"
            graphic = sampleGraphic
            position = Pos.BOTTOM_RIGHT
            owner = stage
            hideAfter = 10.seconds
            onAction { }
            darkStyle()
            hideCloseButton()
            actions()
            threshold(0) { }
        })
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/LineToTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.LineTo
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class LineToTest : LayoutsTest<KtfxPath, LineTo>() {

    override fun manager() = KtfxPath()
    override fun KtfxPath.childCount() = elements.size
    override fun child1() = lineTo { }
    override fun KtfxPath.child2() = lineTo()
    override fun KtfxPath.child3() = lineTo { }

    override fun LineTo.testDefaultValues() {
        assertEquals(0.0, x)
        assertEquals(0.0, y)
    }
}

<|start_filename|>thirdparty/jfoenix-commons/src/ktfx/jfoenix/controls/JFXSnackbar.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.jfoenix.controls

import com.jfoenix.controls.JFXSnackbar
import com.jfoenix.controls.JFXSnackbarLayout
import javafx.event.ActionEvent
import javafx.scene.Node
import javafx.scene.layout.Pane
import javafx.util.Duration

/** Show this snackbar with custom layout. */
inline fun JFXSnackbar.show(content: Node, duration: Duration): Unit =
    enqueue(JFXSnackbar.SnackbarEvent(content, duration))

/** Show this snackbar with default layout. */
fun JFXSnackbar.show(
    message: String,
    duration: Duration,
    actionText: String? = null,
    action: ((ActionEvent) -> Unit)? = null
): Unit = show(
    JFXSnackbarLayout(message, actionText) {
        close()
        action?.invoke(it)
    },
    duration
)

/** Show this snackbar indefinitely with custom layout. */
inline fun JFXSnackbar.showIndefinite(content: Node): Unit =
    enqueue(JFXSnackbar.SnackbarEvent(content, Duration.INDEFINITE))

/** Show this snackbar indefinitely with default layout. */
fun JFXSnackbar.showIndefinite(
    message: String,
    actionText: String? = null,
    action: ((ActionEvent) -> Unit)? = null
): Unit = showIndefinite(
    JFXSnackbarLayout(message, actionText) {
        close()
        action?.invoke(it)
    }
)

/** Create and show a snackbar with custom layout. */
fun Pane.jfxSnackbar(content: Node, duration: Duration): JFXSnackbar =
    JFXSnackbar(this).apply { show(content, duration) }

/** Create and show a snackbar with default layout. */
fun Pane.jfxSnackbar(
    message: String,
    duration: Duration,
    actionText: String? = null,
    action: ((ActionEvent) -> Unit)? = null
): JFXSnackbar = JFXSnackbar(this).apply { show(message, duration, actionText, action) }

/** Create and show an indefinite snackbar with custom layout. */
fun Pane.jfxIndefiniteSnackbar(content: Node): JFXSnackbar =
    JFXSnackbar(this).apply { showIndefinite(content) }

/** Create and show an indefinite snackbar with default layout. */
fun Pane.jfxIndefiniteSnackbar(
    message: String,
    actionText: String? = null,
    action: ((ActionEvent) -> Unit)? = null
): JFXSnackbar = JFXSnackbar(this).apply { showIndefinite(message, actionText, action) }


<|start_filename|>thirdparty/controlsfx-coroutines/tests/src/org/controlsfx/control/PlusMinusSliderTest.kt<|end_filename|>
package ktfx.controlsfx.coroutines

import kotlinx.coroutines.Dispatchers
import ktfx.controlsfx.test.BasePlusMinusSliderTest
import org.controlsfx.control.PlusMinusSlider

class PlusMinusSliderTest : BasePlusMinusSliderTest() {

    override fun PlusMinusSlider.callOnValueChanged(action: (PlusMinusSlider.PlusMinusEvent) -> Unit) =
        onValueChanged(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>testing/listeners-coroutines-controlsfx/build.gradle.kts<|end_filename|>
plugins {
    javafx
    kotlin("jvm")
}

javafx {
    modules("javafx.controls")
}

sourceSets {
    main {
        java.srcDir("src")
        resources.srcDir("res")
    }
}

dependencies {
    api(project(":testing:listeners-coroutines"))
    api(controlsfx())
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_ButtonBase.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.ActionEvent
import javafx.scene.control.ButtonBase
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see ButtonBase.setOnAction
 */
public inline fun ButtonBase.onAction(noinline action: (ActionEvent) -> Unit) {
    return setOnAction(action)
}


<|start_filename|>ktfx-layouts/src/javafx/scene/layout/KtfxPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.layout.Pane
import kotlin.contracts.ExperimentalContracts

/**
 * [Pane] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxPane : Pane(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { children += it }
}


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_ChoiceBox.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.ChoiceBox
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see ChoiceBox.setOnAction
 */
public fun ChoiceBox<*>.onAction(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ActionEvent) -> Unit
) {
    return setOnAction { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ChoiceBox.setOnShowing
 */
public fun ChoiceBox<*>.onShowing(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnShowing { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ChoiceBox.setOnShown
 */
public fun ChoiceBox<*>.onShown(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnShown { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ChoiceBox.setOnHiding
 */
public fun ChoiceBox<*>.onHiding(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnHiding { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ChoiceBox.setOnHidden
 */
public fun ChoiceBox<*>.onHidden(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnHidden { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>thirdparty/jfoenix-listeners/tests/src/com/jfoenix/controls/JFXAutoCompletePopupTest.kt<|end_filename|>
package ktfx.jfoenix.listeners

import com.jfoenix.controls.JFXAutoCompletePopup
import com.jfoenix.controls.events.JFXAutoCompleteEvent
import ktfx.jfoenix.test.BaseJFXAutoCompletePopupTest

class JFXAutoCompletePopupTest : BaseJFXAutoCompletePopupTest() {

    override fun <E> JFXAutoCompletePopup<E>.callSelectionHandler(action: (JFXAutoCompleteEvent<E>) -> Unit) =
        selectionHandler(action)
}

<|start_filename|>thirdparty/controlsfx-listeners/tests/src/org/controlsfx/control/HyperlinkLabelTest.kt<|end_filename|>
package ktfx.controlsfx.listeners

import javafx.event.ActionEvent
import ktfx.controlsfx.test.BaseHyperlinkLabelTest
import org.controlsfx.control.HyperlinkLabel

class HyperlinkLabelTest : BaseHyperlinkLabelTest() {

    override fun HyperlinkLabel.callOnAction(action: (ActionEvent) -> Unit) =
        onAction(action)
}

<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/controls/Borders.kt<|end_filename|>
@file:JvmName("ControlsFxBordersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.controls

import javafx.scene.Node
import javafx.scene.layout.BorderStrokeStyle
import javafx.scene.paint.Color
import ktfx.internal.KtfxInternals.NO_GETTER
import ktfx.internal.KtfxInternals.noGetter
import org.controlsfx.tools.Borders
import kotlin.DeprecationLevel.ERROR

/** Wraps this [Node] with borders using Kotlin DSL, returning the wrapped node. */
fun Node.wrapBorders(builderAction: BordersBuilder.() -> Unit): Node =
    BordersBuilder(this).apply(builderAction).build()

/** Add a new [Borders.EmptyBorders] to node using DSL. */
inline fun Node.wrapEmptyBorder(noinline builderAction: BordersBuilder.EmptyBuilder.() -> Unit): Node =
    wrapBorders { empty(builderAction) }

/** Add a new [Borders.EtchedBorders] to node using DSL. */
inline fun Node.wrapEtchedBorder(noinline builderAction: BordersBuilder.EtchedBuilder.() -> Unit): Node =
    wrapBorders { etched(builderAction) }

/** Add a new [Borders.LineBorders] to node using DSL. */
inline fun Node.wrapLineBorder(noinline builderAction: BordersBuilder.LineBuilder.() -> Unit): Node =
    wrapBorders { line(builderAction) }

/**
 * Supporting class to use [Borders] with DSL.
 * @see Node.wrapBorders
 */
class BordersBuilder internal constructor(node: Node) {
    private val nativeBorders: Borders = Borders.wrap(node)

    /** Opens up DSL to create empty border. */
    fun empty(builderAction: EmptyBuilder.() -> Unit): Unit =
        EmptyBuilder(nativeBorders.emptyBorder()).apply(builderAction).build()

    /** Opens up DSL to create etched border. */
    fun etched(builderAction: EtchedBuilder.() -> Unit): Unit =
        EtchedBuilder(nativeBorders.etchedBorder()).apply(builderAction).build()

    /** Opens up DSL to create line border. */
    fun line(builderAction: LineBuilder.() -> Unit): Unit =
        LineBuilder(nativeBorders.lineBorder()).apply(builderAction).build()

    /** Allows for developers to develop custom [Borders.Border] implementations. */
    fun addBorder(border: Borders.Border) {
        nativeBorders.addBorder(border)
    }

    internal fun build(): Node = nativeBorders.build()

    /** Supporting class to add empty border with DSL. */
    class EmptyBuilder internal constructor(private val nativeBorders: Borders.EmptyBorders) {

        /** Specifies that the wrapped Node should have the given padding around all four sides of itself. */
        var padding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.padding(value)
            }

        /** Specifies that the wrapped Node should be wrapped with the given padding for each of its four sides */
        fun padding(top: Double, right: Double, bottom: Double, left: Double) {
            nativeBorders.padding(top, right, bottom, left)
        }

        var topPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = padding(value, 0.0, 0.0, 0.0)

        var rightPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = padding(0.0, value, 0.0, 0.0)

        var bottomPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = padding(0.0, 0.0, value, 0.0)

        var leftPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = padding(0.0, 0.0, 0.0, value)

        internal fun build() {
            nativeBorders.build()
        }
    }

    abstract class NonEmptyBordersBuilder internal constructor() {

        /** If desired, this specifies the title text to show in this border. */
        abstract var title: String

        /** Specifies the outer padding of the four lines of this border. */
        abstract var outerPadding: Double

        /** Specifies that the line wrapping the node should have outer padding as specified. */
        abstract fun outerPadding(top: Double, right: Double, bottom: Double, left: Double)

        var outerTopPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = outerPadding(value, 0.0, 0.0, 0.0)

        var outerRightPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = outerPadding(0.0, value, 0.0, 0.0)

        var outerBottomPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = outerPadding(0.0, 0.0, value, 0.0)

        var outerLeftPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = outerPadding(0.0, 0.0, 0.0, value)

        /** Specifies the inner padding of the four lines of this border. */
        abstract var innerPadding: Double

        /** Specifies that the line wrapping the node should have inner padding as specified. */
        abstract fun innerPadding(top: Double, right: Double, bottom: Double, left: Double)

        var innerTopPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = innerPadding(value, 0.0, 0.0, 0.0)

        var innerRightPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = innerPadding(0.0, value, 0.0, 0.0)

        var innerBottomPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = innerPadding(0.0, 0.0, value, 0.0)

        var innerLeftPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            inline set(value) = innerPadding(0.0, 0.0, 0.0, value)

        /** Specifies the radius of the four corners of the line of this border. */
        abstract var radius: Double

        /** Specifies that the line wrapping the node should have corner radii as specified. */
        abstract fun radius(top: Double, right: Double, bottom: Double, left: Double)
    }

    /** Supporting class to add etched border with DSL. */
    class EtchedBuilder internal constructor(private val nativeBorders: Borders.EtchedBorders) :
        NonEmptyBordersBuilder() {

        /** Specifies the highlight colour to use in the etched border. */
        var highlight: Color
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.highlight(value)
            }

        /** Specifies the shadow colour to use in the etched border. */
        var shadow: Color
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.shadow(value)
            }

        /** Specifies the order in which the highlight and shadow colours are placed. */
        fun raised() {
            nativeBorders.raised()
        }

        override var title: String
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.title(value)
            }

        override var outerPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.outerPadding(value)
            }

        override fun outerPadding(top: Double, right: Double, bottom: Double, left: Double) {
            nativeBorders.outerPadding(top, right, bottom, left)
        }

        override var innerPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.innerPadding(value)
            }

        override fun innerPadding(top: Double, right: Double, bottom: Double, left: Double) {
            nativeBorders.innerPadding(top, right, bottom, left)
        }

        override var radius: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.radius(value)
            }

        override fun radius(top: Double, right: Double, bottom: Double, left: Double) {
            nativeBorders.radius(top, right, bottom, left)
        }

        internal fun build() {
            nativeBorders.build()
        }
    }

    /** Supporting class to add line border with DSL. */
    class LineBuilder internal constructor(private val nativeBorders: Borders.LineBorders) :
        NonEmptyBordersBuilder() {

        /** Specifies the colour to use for all four sides of this border. */
        var color: Color
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.color(value)
            }

        /** Specifies that the wrapped Node should be wrapped with the given colours for each of its four sides. */
        fun color(top: Color, right: Color, bottom: Color, left: Color) {
            nativeBorders.color(top, right, bottom, left)
        }

        /** Specifies which {@link BorderStrokeStyle} to use for this line border. */
        var strokeStyle: BorderStrokeStyle
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.strokeStyle(value)
            }

        override var outerPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.outerPadding(value)
            }

        override fun outerPadding(top: Double, right: Double, bottom: Double, left: Double) {
            nativeBorders.outerPadding(top, right, bottom, left)
        }

        override var innerPadding: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.innerPadding(value)
            }

        override fun innerPadding(top: Double, right: Double, bottom: Double, left: Double) {
            nativeBorders.innerPadding(top, right, bottom, left)
        }

        /** Specifies the thickness of the line to use on all four sides of this border. */
        var thickness: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.thickness(value)
            }

        /** Specifies that the wrapped Node should be wrapped with the given line thickness for each of its four sides. */
        fun thickness(top: Double, right: Double, bottom: Double, left: Double) {
            nativeBorders.thickness(top, right, bottom, left)
        }

        override var radius: Double
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.radius(value)
            }

        override fun radius(top: Double, right: Double, bottom: Double, left: Double) {
            nativeBorders.radius(top, right, bottom, left)
        }

        override var title: String
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                nativeBorders.title(value)
            }

        internal fun build() {
            nativeBorders.build()
        }
    }
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_HLineTo.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.HLineTo
import kotlin.Double
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [HLineTo] to this manager.
 *
 * @return the control added.
 */
public fun PathElementManager.hlineTo(x: Double = 0.0): HLineTo = hlineTo(x = x) { }

/**
 * Create a [HLineTo] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun hlineTo(
    x: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker HLineTo).() ->    
    Unit
): HLineTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = HLineTo(x)
    child.configuration()
    return child
}

/**
 * Add a [HLineTo] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun PathElementManager.hlineTo(
    x: Double = 0.0,
    configuration: (
        @KtfxLayoutDslMarker    
        HLineTo
    ).() -> Unit
): HLineTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = HLineTo(x)
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/inputs/MouseEventTest.kt<|end_filename|>
package ktfx.inputs

import javafx.scene.input.MouseButton
import javafx.scene.input.MouseEvent
import com.hendraanggrian.ktfx.test.BaseInputTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertTrue

@Ignore
class MouseEventTest : BaseInputTest() {

    @Test
    fun isLeftClick() = assertTrue {
        mouseEventOf(MouseEvent.MOUSE_CLICKED, sceneMouseX, sceneMouseY, MouseButton.PRIMARY, 1).isLeftClick()
    }

    @Test
    fun isRightClick() = assertTrue {
        mouseEventOf(MouseEvent.MOUSE_CLICKED, sceneMouseX, sceneMouseY, MouseButton.SECONDARY, 1).isRightClick()
    }

    @Test
    fun isMiddleClick() = assertTrue {
        mouseEventOf(MouseEvent.MOUSE_CLICKED, sceneMouseX, sceneMouseY, MouseButton.MIDDLE, 1).isMiddleClick()
    }

    @Test
    fun isDoubleClick() = assertTrue {
        mouseEventOf(MouseEvent.MOUSE_CLICKED, sceneMouseX, sceneMouseY, MouseButton.PRIMARY, 2).isDoubleClick()
    }
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXNodesListTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXNodesList
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXNodesListTest : LayoutsTest<KtfxPane, JFXNodesList>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxNodesList { }
    override fun KtfxPane.child2() = jfxNodesList()
    override fun KtfxPane.child3() = jfxNodesList { }
}

<|start_filename|>testing/listeners-coroutines/src/com/hendraanggrian/ktfx/test/events/FakeScrollEvent.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.EventType
import javafx.scene.input.ScrollEvent
import kotlin.test.assertEquals
import kotlin.test.assertFalse

/**
 * @receiver source of this fake event.
 */
fun Any.assertFakeScrollEvent(actual: ScrollEvent, expectedType: EventType<ScrollEvent>) {
    assertEquals(this, actual.source)
    assertEquals(FakeEventTarget, actual.target)
    assertEquals(expectedType, actual.eventType)
    assertEquals(0.0, actual.x)
    assertEquals(0.0, actual.y)
    assertEquals(0.0, actual.screenX)
    assertEquals(0.0, actual.screenY)
    assertFalse(actual.isShiftDown)
    assertFalse(actual.isControlDown)
    assertFalse(actual.isAltDown)
    assertFalse(actual.isMetaDown)
    assertFalse(actual.isDirect)
    assertFalse(actual.isInertia)
    assertEquals(0.0, actual.deltaX)
    assertEquals(0.0, actual.deltaY)
    assertEquals(0.0, actual.totalDeltaX)
    assertEquals(0.0, actual.totalDeltaY)
    assertEquals(ScrollEvent.HorizontalTextScrollUnits.CHARACTERS, actual.textDeltaXUnits)
    assertEquals(ScrollEvent.VerticalTextScrollUnits.LINES, actual.textDeltaYUnits)
    assertEquals(0, actual.touchCount)
    assertEquals(FakePickResult, actual.pickResult)
}

/**
 * @receiver source of this fake event.
 */
fun Any.fakeScrollEventOf(eventType: EventType<ScrollEvent>) = ScrollEvent(
    this, FakeEventTarget,
    eventType,
    0.0, 0.0,
    0.0, 0.0,
    false,
    false,
    false,
    false,
    false,
    false,
    0.0, 0.0,
    0.0, 0.0,
    ScrollEvent.HorizontalTextScrollUnits.CHARACTERS, 0.0,
    ScrollEvent.VerticalTextScrollUnits.LINES, 0.0,
    0, FakePickResult
)

<|start_filename|>ktfx-commons/src/ktfx/inputs/KeyEvent.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.inputs

import javafx.scene.input.KeyCode
import javafx.scene.input.KeyEvent

/** Returns true if this key is delete or backspace. */
inline fun KeyEvent.isDelete(): Boolean = code == KeyCode.DELETE || code == KeyCode.BACK_SPACE

/** Returns true if this key is number softkey or numpad 0. */
inline fun KeyEvent.is0(): Boolean = code == KeyCode.NUMPAD0 || code == KeyCode.SOFTKEY_0

/** Returns true if this key is number softkey or numpad 1. */
inline fun KeyEvent.is1(): Boolean = code == KeyCode.NUMPAD1 || code == KeyCode.SOFTKEY_1

/** Returns true if this key is number softkey or numpad 2. */
inline fun KeyEvent.is2(): Boolean = code == KeyCode.NUMPAD2 || code == KeyCode.SOFTKEY_2

/** Returns true if this key is number softkey or numpad 3. */
inline fun KeyEvent.is3(): Boolean = code == KeyCode.NUMPAD3 || code == KeyCode.SOFTKEY_3

/** Returns true if this key is number softkey or numpad 4. */
inline fun KeyEvent.is4(): Boolean = code == KeyCode.NUMPAD4 || code == KeyCode.SOFTKEY_4

/** Returns true if this key is number softkey or numpad 5. */
inline fun KeyEvent.is5(): Boolean = code == KeyCode.NUMPAD5 || code == KeyCode.SOFTKEY_5

/** Returns true if this key is number softkey or numpad 6. */
inline fun KeyEvent.is6(): Boolean = code == KeyCode.NUMPAD6 || code == KeyCode.SOFTKEY_6

/** Returns true if this key is number softkey or numpad 7. */
inline fun KeyEvent.is7(): Boolean = code == KeyCode.NUMPAD7 || code == KeyCode.SOFTKEY_7

/** Returns true if this key is number softkey or numpad 8. */
inline fun KeyEvent.is8(): Boolean = code == KeyCode.NUMPAD8 || code == KeyCode.SOFTKEY_8

/** Returns true if this key is number softkey or numpad 9. */
inline fun KeyEvent.is9(): Boolean = code == KeyCode.NUMPAD9 || code == KeyCode.SOFTKEY_9


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_WebEngine.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.geometry.Rectangle2D
import javafx.scene.web.WebEngine
import javafx.scene.web.WebErrorEvent
import javafx.scene.web.WebEvent
import kotlin.Boolean
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see WebEngine.setOnAlert
 */
public inline fun WebEngine.onAlert(noinline action: (WebEvent<String>) -> Unit) {
    return setOnAlert(action)
}

/**
 * @see WebEngine.setOnStatusChanged
 */
public inline fun WebEngine.onStatusChanged(noinline action: (WebEvent<String>) -> Unit) {
    return setOnStatusChanged(action)
}

/**
 * @see WebEngine.setOnResized
 */
public inline fun WebEngine.onResized(noinline action: (WebEvent<Rectangle2D>) -> Unit) {
    return setOnResized(action)
}

/**
 * @see WebEngine.setOnVisibilityChanged
 */
public inline fun WebEngine.onVisibilityChanged(noinline action: (WebEvent<Boolean>) -> Unit) {
    return setOnVisibilityChanged(action)
}

/**
 * @see WebEngine.setOnError
 */
public inline fun WebEngine.onError(noinline action: (WebErrorEvent) -> Unit) {
    return setOnError(action)
}


<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/ComboBoxBaseTest.kt<|end_filename|>
package ktfx.listeners

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.ComboBoxBase
import com.hendraanggrian.ktfx.test.BaseComboBoxBaseTest

class ComboBoxBaseTest : BaseComboBoxBaseTest() {

    override fun <E> ComboBoxBase<E>.callOnAction(action: (ActionEvent) -> Unit) = onAction(action)
    override fun <E> ComboBoxBase<E>.callOnShowing(action: (Event) -> Unit) = onShowing(action)
    override fun <E> ComboBoxBase<E>.callOnShown(action: (Event) -> Unit) = onShown(action)
    override fun <E> ComboBoxBase<E>.callOnHiding(action: (Event) -> Unit) = onHiding(action)
    override fun <E> ComboBoxBase<E>.callOnHidden(action: (Event) -> Unit) = onHidden(action)
}

<|start_filename|>rulesets/basic/src/com/hendraanggrian/ktfx/rules/ExpressionFunctionReturnTypeRule.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.pinterest.ktlint.core.Rule
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes

/** Expression function and property must have return type. */
class ExpressionFunctionReturnTypeRule : Rule("expression-function-return-type") {

    override fun visit(node: ASTNode, autoCorrect: Boolean, emit: (Int, String, Boolean) -> Unit) {
        val typeName = when {
            node.elementType == KtStubElementTypes.FUNCTION &&
                node.findChildByType(KtNodeTypes.BLOCK) == null -> "Expression function"
            node.elementType == KtStubElementTypes.PROPERTY -> "Property"
            else -> return
        }

        // only check top-level declaration
        if (node.treeParent?.elementType != KtStubElementTypes.FILE) {
            return
        }

        if (node.findChildByType(KtStubElementTypes.TYPE_REFERENCE) == null) {
            emit(node.startOffset, "$typeName need return type", false)
        }
    }
}


<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/dialogs/FontSelectors.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.dialogs

import javafx.scene.Node
import javafx.scene.image.ImageView
import javafx.scene.text.Font
import ktfx.dialogs.graphicIcon
import ktfx.dialogs.headerTitle
import org.controlsfx.dialog.FontSelectorDialog
import java.util.Optional

/**
 * Build a font selector dialog with Kotlin DSL.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param defaultFont initially selected font.
 * @param dialogAction custom dialog action.
 * @return selected font.
 */
fun fontSelector(
    title: String? = null,
    graphic: Node? = null,
    defaultFont: Font? = null,
    dialogAction: (FontSelectorDialog.() -> Unit)? = null
): Optional<Font> = FontSelectorDialog(defaultFont).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    dialogAction?.invoke(dialog)
}.showAndWait()

/**
 * Build a font selector dialog with Kotlin DSL.
 * @param defaultFont initially selected font.
 * @param dialogAction custom dialog action.
 * @return selected font.
 */
inline fun fontSelector(
    defaultFont: Font? = null,
    noinline dialogAction: (FontSelectorDialog.() -> Unit)? = null
): Optional<Font> = fontSelector(null, null, defaultFont, dialogAction)


<|start_filename|>ktfx-listeners/tests/src/javafx/animation/AnimationTest.kt<|end_filename|>
package ktfx.listeners

import javafx.animation.Animation
import javafx.event.ActionEvent
import com.hendraanggrian.ktfx.test.BaseAnimationTest

class AnimationTest : BaseAnimationTest() {

    override fun Animation.callOnFinished(action: (ActionEvent) -> Unit) = onFinished(action)
}

<|start_filename|>ktfx-commons/tests/src/ktfx/collections/ObservableArraysFloatTest.kt<|end_filename|>
package ktfx.collections

import javafx.collections.ObservableFloatArray
import com.hendraanggrian.ktfx.test.BaseArraysTest

class ObservableArraysFloatTest : BaseArraysTest<ObservableFloatArray, FloatArray, Float>() {

    override val typedArray = arrayOf(1f, 2f, 3f)
    override val primitiveArray = floatArrayOf(1f, 2f, 3f)

    override fun of() = observableFloatArrayOf()
    override fun of(values: Array<Float>) = observableFloatArrayOf(*values.toFloatArray())

    override fun FloatArray.to() = toObservableArray()
}


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_Scene.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.Scene
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Scene.setOnMouseClicked
 */
public inline fun Scene.onMouseClicked(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseClicked(action)
}

/**
 * @see Scene.setOnMouseDragged
 */
public inline fun Scene.onMouseDragged(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseDragged(action)
}

/**
 * @see Scene.setOnMouseEntered
 */
public inline fun Scene.onMouseEntered(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseEntered(action)
}

/**
 * @see Scene.setOnMouseExited
 */
public inline fun Scene.onMouseExited(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseExited(action)
}

/**
 * @see Scene.setOnMouseMoved
 */
public inline fun Scene.onMouseMoved(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseMoved(action)
}

/**
 * @see Scene.setOnMousePressed
 */
public inline fun Scene.onMousePressed(noinline action: (MouseEvent) -> Unit) {
    return setOnMousePressed(action)
}

/**
 * @see Scene.setOnMouseReleased
 */
public inline fun Scene.onMouseReleased(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseReleased(action)
}

/**
 * @see Scene.setOnDragDetected
 */
public inline fun Scene.onDragDetected(noinline action: (MouseEvent) -> Unit) {
    return setOnDragDetected(action)
}

/**
 * @see Scene.setOnMouseDragOver
 */
public inline fun Scene.onMouseDragOver(noinline action: (MouseDragEvent) -> Unit) {
    return setOnMouseDragOver(action)
}

/**
 * @see Scene.setOnMouseDragReleased
 */
public inline fun Scene.onMouseDragReleased(noinline action: (MouseDragEvent) -> Unit) {
    return setOnMouseDragReleased(action)
}

/**
 * @see Scene.setOnMouseDragEntered
 */
public inline fun Scene.onMouseDragEntered(noinline action: (MouseDragEvent) -> Unit) {
    return setOnMouseDragEntered(action)
}

/**
 * @see Scene.setOnMouseDragExited
 */
public inline fun Scene.onMouseDragExited(noinline action: (MouseDragEvent) -> Unit) {
    return setOnMouseDragExited(action)
}

/**
 * @see Scene.setOnScrollStarted
 */
public inline fun Scene.onScrollStarted(noinline action: (ScrollEvent) -> Unit) {
    return setOnScrollStarted(action)
}

/**
 * @see Scene.setOnScroll
 */
public inline fun Scene.onScroll(noinline action: (ScrollEvent) -> Unit) {
    return setOnScroll(action)
}

/**
 * @see Scene.setOnScrollFinished
 */
public inline fun Scene.onScrollFinished(noinline action: (ScrollEvent) -> Unit) {
    return setOnScrollFinished(action)
}

/**
 * @see Scene.setOnRotationStarted
 */
public inline fun Scene.onRotationStarted(noinline action: (RotateEvent) -> Unit) {
    return setOnRotationStarted(action)
}

/**
 * @see Scene.setOnRotate
 */
public inline fun Scene.onRotate(noinline action: (RotateEvent) -> Unit) {
    return setOnRotate(action)
}

/**
 * @see Scene.setOnRotationFinished
 */
public inline fun Scene.onRotationFinished(noinline action: (RotateEvent) -> Unit) {
    return setOnRotationFinished(action)
}

/**
 * @see Scene.setOnZoomStarted
 */
public inline fun Scene.onZoomStarted(noinline action: (ZoomEvent) -> Unit) {
    return setOnZoomStarted(action)
}

/**
 * @see Scene.setOnZoom
 */
public inline fun Scene.onZoom(noinline action: (ZoomEvent) -> Unit) {
    return setOnZoom(action)
}

/**
 * @see Scene.setOnZoomFinished
 */
public inline fun Scene.onZoomFinished(noinline action: (ZoomEvent) -> Unit) {
    return setOnZoomFinished(action)
}

/**
 * @see Scene.setOnSwipeUp
 */
public inline fun Scene.onSwipeUp(noinline action: (SwipeEvent) -> Unit) {
    return setOnSwipeUp(action)
}

/**
 * @see Scene.setOnSwipeDown
 */
public inline fun Scene.onSwipeDown(noinline action: (SwipeEvent) -> Unit) {
    return setOnSwipeDown(action)
}

/**
 * @see Scene.setOnSwipeLeft
 */
public inline fun Scene.onSwipeLeft(noinline action: (SwipeEvent) -> Unit) {
    return setOnSwipeLeft(action)
}

/**
 * @see Scene.setOnSwipeRight
 */
public inline fun Scene.onSwipeRight(noinline action: (SwipeEvent) -> Unit) {
    return setOnSwipeRight(action)
}

/**
 * @see Scene.setOnTouchPressed
 */
public inline fun Scene.onTouchPressed(noinline action: (TouchEvent) -> Unit) {
    return setOnTouchPressed(action)
}

/**
 * @see Scene.setOnTouchMoved
 */
public inline fun Scene.onTouchMoved(noinline action: (TouchEvent) -> Unit) {
    return setOnTouchMoved(action)
}

/**
 * @see Scene.setOnTouchReleased
 */
public inline fun Scene.onTouchReleased(noinline action: (TouchEvent) -> Unit) {
    return setOnTouchReleased(action)
}

/**
 * @see Scene.setOnTouchStationary
 */
public inline fun Scene.onTouchStationary(noinline action: (TouchEvent) -> Unit) {
    return setOnTouchStationary(action)
}

/**
 * @see Scene.setOnDragEntered
 */
public inline fun Scene.onDragEntered(noinline action: (DragEvent) -> Unit) {
    return setOnDragEntered(action)
}

/**
 * @see Scene.setOnDragExited
 */
public inline fun Scene.onDragExited(noinline action: (DragEvent) -> Unit) {
    return setOnDragExited(action)
}

/**
 * @see Scene.setOnDragOver
 */
public inline fun Scene.onDragOver(noinline action: (DragEvent) -> Unit) {
    return setOnDragOver(action)
}

/**
 * @see Scene.setOnDragDropped
 */
public inline fun Scene.onDragDropped(noinline action: (DragEvent) -> Unit) {
    return setOnDragDropped(action)
}

/**
 * @see Scene.setOnDragDone
 */
public inline fun Scene.onDragDone(noinline action: (DragEvent) -> Unit) {
    return setOnDragDone(action)
}

/**
 * @see Scene.setOnKeyPressed
 */
public inline fun Scene.onKeyPressed(noinline action: (KeyEvent) -> Unit) {
    return setOnKeyPressed(action)
}

/**
 * @see Scene.setOnKeyReleased
 */
public inline fun Scene.onKeyReleased(noinline action: (KeyEvent) -> Unit) {
    return setOnKeyReleased(action)
}

/**
 * @see Scene.setOnKeyTyped
 */
public inline fun Scene.onKeyTyped(noinline action: (KeyEvent) -> Unit) {
    return setOnKeyTyped(action)
}

/**
 * @see Scene.setOnInputMethodTextChanged
 */
public inline fun Scene.onInputMethodTextChanged(noinline action: (InputMethodEvent) -> Unit) {
    return setOnInputMethodTextChanged(action)
}

/**
 * @see Scene.setOnContextMenuRequested
 */
public inline fun Scene.onContextMenuRequested(noinline action: (ContextMenuEvent) -> Unit) {
    return setOnContextMenuRequested(action)
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/MasterDetailPaneTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import javafx.geometry.Side
import ktfx.layouts.KtfxPane
import ktfx.layouts.pane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.MasterDetailPane
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertTrue

class MasterDetailPaneTest : LayoutsTest<KtfxPane, MasterDetailPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = masterDetailPane { }
    override fun KtfxPane.child2() = masterDetailPane()
    override fun KtfxPane.child3() = masterDetailPane { }

    override fun MasterDetailPane.testDefaultValues() {
        assertEquals(Side.RIGHT, detailSide)
        assertTrue(isShowDetailNode)
    }

    @Test
    fun illegalThirdNode() {
        assertFailsWith<IllegalStateException> {
            masterDetailPane {
                pane()
                pane()
                pane()
            }
        }
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/CircleTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.Circle
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals
import kotlin.test.assertNull

class CircleTest : LayoutsTest<KtfxPane, Circle>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = circle { }
    override fun KtfxPane.child2() = circle()
    override fun KtfxPane.child3() = circle { }

    override fun Circle.testDefaultValues() {
        assertEquals(0.0, centerX)
        assertEquals(0.0, centerY)
        assertEquals(0.0, radius)
        assertNull(fill)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/PaginationTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.Pagination
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class PaginationTest : LayoutsTest<KtfxPane, Pagination>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = pagination { }
    override fun KtfxPane.child2() = pagination()
    override fun KtfxPane.child3() = pagination { }

    override fun Pagination.testDefaultValues() {
        assertEquals(Pagination.INDETERMINATE, pageCount)
        assertEquals(0, currentPageIndex)
    }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/BindingsBooleanTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.booleanPropertyOf
import ktfx.collections.mutableObservableListOf
import ktfx.collections.mutableObservableMapOf
import ktfx.collections.mutableObservableSetOf
import ktfx.doublePropertyOf
import ktfx.floatPropertyOf
import ktfx.intPropertyOf
import ktfx.longPropertyOf
import ktfx.propertyOf
import ktfx.time.minutes
import ktfx.time.seconds
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class BindingsBooleanTest {

    @Test
    fun multipleDependencies() {
        val dependency1 = booleanPropertyOf(true)
        val dependency2 = booleanPropertyOf(true)
        val binding1 = booleanBindingOf(dependency1, dependency2) { dependency1.value && dependency2.value }
        assertTrue(binding1.value)
        dependency1.value = false
        assertFalse(binding1.value)

        val dependency3 = booleanPropertyOf(true)
        val dependency4 = booleanPropertyOf(true)
        val binding2 = booleanBindingOf(listOf(dependency3, dependency4)) { dependency3.value && dependency4.value }
        assertTrue(binding2.value)
        dependency3.value = false
        assertFalse(binding2.value)
    }

    @Test
    fun listDependency() {
        val dependency = mutableObservableListOf(1.minutes)
        val binding = dependency.asBoolean { it.isNotEmpty() }
        assertTrue(binding.value)
        dependency.clear()
        assertFalse(binding.value)
    }

    @Test
    fun setDependency() {
        val dependency = mutableObservableSetOf(1.minutes)
        val binding = dependency.asBoolean { it.isNotEmpty() }
        assertTrue(binding.value)
        dependency.clear()
        assertFalse(binding.value)
    }

    @Test
    fun mapDependency() {
        val dependency = mutableObservableMapOf(1.minutes to 2.minutes)
        val binding = dependency.asBoolean { it.isNotEmpty() }
        assertTrue(binding.value)
        dependency.clear()
        assertFalse(binding.value)
    }

    @Test
    fun anyDependency() {
        val dependency = propertyOf(1.minutes)
        val binding = dependency.asBoolean { it == 60.seconds }
        assertTrue(binding.value)
        dependency.value = null
        assertFalse(binding.value)
    }

    @Test
    fun booleanDependency() {
        val dependency = booleanPropertyOf()
        val binding = dependency.asBoolean { !it }
        assertTrue(binding.value)
        dependency.value = true
        assertFalse(binding.value)
    }

    @Test
    fun doubleDependency() {
        val dependency = doublePropertyOf()
        val binding = dependency.asBoolean { it == 0.0 }
        assertTrue(binding.value)
        dependency.value = Double.MAX_VALUE
        assertFalse(binding.value)
    }

    @Test
    fun floatDependency() {
        val dependency = floatPropertyOf()
        val binding = dependency.asBoolean { it == 0f }
        assertTrue(binding.value)
        dependency.value = Float.MAX_VALUE
        assertFalse(binding.value)
    }

    @Test
    fun intDependency() {
        val dependency = intPropertyOf()
        val binding = dependency.asBoolean { it == 0 }
        assertTrue(binding.value)
        dependency.value = Int.MAX_VALUE
        assertFalse(binding.value)
    }

    @Test
    fun longDependency() {
        val dependency = longPropertyOf()
        val binding = dependency.asBoolean { it == 0L }
        assertTrue(binding.value)
        dependency.value = Long.MAX_VALUE
        assertFalse(binding.value)
    }
}


<|start_filename|>testing/listeners-coroutines/src/com/hendraanggrian/ktfx/test/FakePickResult.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.input.PickResult

object FakePickResult : PickResult(FakeEventTarget, 0.0, 0.0)

<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/BindingsFloatTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.booleanPropertyOf
import ktfx.doublePropertyOf
import ktfx.floatPropertyOf
import ktfx.intPropertyOf
import ktfx.longPropertyOf
import ktfx.propertyOf
import ktfx.time.minutes
import kotlin.test.Test
import kotlin.test.assertEquals

class BindingsFloatTest {

    @Test
    fun multipleDependencies() {
        val dependency1 = floatPropertyOf(1f)
        val dependency2 = floatPropertyOf(2f)
        val binding1 = floatBindingOf(dependency1, dependency2) { dependency1.value + dependency2.value }
        assertEquals(3f, binding1.value)
        dependency1.value++
        assertEquals(4f, binding1.value)

        val dependency3 = floatPropertyOf(1f)
        val dependency4 = floatPropertyOf(2f)
        val binding2 = floatBindingOf(listOf(dependency3, dependency4)) { dependency3.value + dependency4.value }
        assertEquals(3f, binding2.value)
        dependency3.value++
        assertEquals(4f, binding2.value)
    }

    @Test
    fun anyDependency() {
        val dependency = propertyOf(1.minutes)
        val binding = dependency.asFloat { it?.toMillis()?.toFloat() ?: 0f }
        assertEquals(60000f, binding.value)
        dependency.value = null
        assertEquals(0f, binding.value)
    }

    @Test
    fun booleanDependency() {
        val dependency = booleanPropertyOf()
        val binding = dependency.asFloat { if (it) Float.MAX_VALUE else Float.MIN_VALUE }
        assertEquals(Float.MIN_VALUE, binding.value)
        dependency.value = true
        assertEquals(Float.MAX_VALUE, binding.value)
    }

    @Test
    fun doubleDependency() {
        val dependency = doublePropertyOf()
        val binding = dependency.asFloat { it.toFloat() }
        assertEquals(0f, binding.value)
        dependency.value = Double.MAX_VALUE
        assertEquals(Double.MAX_VALUE.toFloat(), binding.value)
    }

    @Test
    fun floatDependency() {
        val dependency = floatPropertyOf()
        val binding = dependency.asFloat { it }
        assertEquals(0f, binding.value)
        dependency.value = Float.MAX_VALUE
        assertEquals(Float.MAX_VALUE, binding.value)
    }

    @Test
    fun intDependency() {
        val dependency = intPropertyOf()
        val binding = dependency.asFloat { it.toFloat() }
        assertEquals(0f, binding.value)
        dependency.value = Int.MAX_VALUE
        assertEquals(Int.MAX_VALUE.toFloat(), binding.value)
    }

    @Test
    fun longDependency() {
        val dependency = longPropertyOf()
        val binding = dependency.asFloat { it.toFloat() }
        assertEquals(0f, binding.value)
        dependency.value = Long.MAX_VALUE
        assertEquals(Long.MAX_VALUE.toFloat(), binding.value)
    }
}


<|start_filename|>thirdparty/jfoenix-commons/tests/src/ktfx/jfoenix/controls/JFXSnackbarTest.kt<|end_filename|>
package ktfx.jfoenix.controls

import com.hendraanggrian.ktfx.test.initToolkit
import javafx.scene.control.Label
import javafx.scene.layout.Pane
import ktfx.time.seconds
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertNotNull

class JFXSnackbarTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun jfxSnackbar() {
        val pane = Pane()
        assertNotNull(pane.jfxSnackbar("Hello world", 5.seconds))
    }

    @Test
    fun jfxIndefiniteSnackbar() {
        val pane = Pane()
        assertNotNull(pane.jfxIndefiniteSnackbar(Label("Hello world")))
    }
}

<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/controls/ValidationSupportTest.kt<|end_filename|>
package ktfx.controlsfx.controls

import javafx.scene.control.TextField
import javafx.stage.Stage
import ktfx.layouts.scene
import ktfx.layouts.textField
import org.controlsfx.validation.ValidationSupport
import org.testfx.framework.junit.ApplicationTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class ValidationSupportTest : ApplicationTest() {
    private lateinit var support: ValidationSupport
    private lateinit var textField: TextField

    override fun start(stage: Stage) {
        support = ValidationSupport()
        stage.scene { textField = textField() }
        stage.show()
    }

    @Test
    fun registerEmptyValidator() {
        textField.registerEmptyValidator<String>("", support = support)
        assertEquals(1, support.registeredControls.size)
        clickOn(textField)
        assertTrue(support.isInvalid)
        write("Hello world")
        assertFalse(support.isInvalid)
    }

    @Test
    fun registerEqualsValidator() {
        textField.registerEqualsValidator("", listOf("Hello", "world"), support = support)
        assertEquals(1, support.registeredControls.size)
        clickOn(textField)
        assertTrue(support.isInvalid)
        write("Hello")
        assertFalse(support.isInvalid)
    }

    @Test
    fun registerPredicateValidator() {
        textField.registerPredicateValidator<String>("", support = support) { it.toIntOrNull() != null }
        assertEquals(1, support.registeredControls.size)
        clickOn(textField)
        assertTrue(support.isInvalid)
        write("123")
        assertFalse(support.isInvalid)
    }
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/beans/ObservableTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.beans.Observable
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseObservableTest

class ObservableTest : BaseObservableTest() {

    override fun Observable.callListener(action: (Observable) -> Unit) {
        listener(Dispatchers.Unconfined) { action(it) }
    }
}

<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/controls/Notifications.kt<|end_filename|>
package ktfx.controlsfx.controls

import javafx.event.ActionEvent
import javafx.geometry.Pos
import javafx.scene.Node
import javafx.util.Duration
import ktfx.internal.KtfxInternals.NO_GETTER
import ktfx.internal.KtfxInternals.noGetter
import org.controlsfx.control.Notifications
import org.controlsfx.control.action.Action
import kotlin.DeprecationLevel.ERROR

/** Build notifications with Kotlin DSL. */
fun buildNotifications(builderAction: NotificationsBuilder.() -> Unit): Notifications =
    NotificationsBuilder().apply(builderAction).nativeNotifications

/** Supporting class to use [Notifications] with DSL. */
class NotificationsBuilder internal constructor() {
    internal val nativeNotifications: Notifications = Notifications.create()

    /** Specify the text to show in the notification. */
    var text: String
        @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
        set(value) {
            nativeNotifications.text(value)
        }

    /** Specify the title to show in the notification. */
    var title: String
        @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
        set(value) {
            nativeNotifications.title(value)
        }

    /** Specify the graphic to show in the notification. */
    var graphic: Node
        @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
        set(value) {
            nativeNotifications.graphic(value)
        }

    /** Specify the position of the notification on screen, by default it is [Pos.BOTTOM_RIGHT]. */
    var position: Pos
        @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
        set(value) {
            nativeNotifications.position(value)
        }

    /** The dialog window owner - which can be [javafx.stage.Screen], [javafx.stage.Window], or [javafx.scene.Node]. */
    var owner: Any
        @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
        set(value) {
            nativeNotifications.owner(value)
        }

    /** Specify the duration that the notification should show, after which it will be hidden. */
    var hideAfter: Duration
        @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
        set(value) {
            nativeNotifications.hideAfter(value)
        }

    /** Specify what to do when the user clicks on the notification. */
    fun onAction(action: (ActionEvent) -> Unit) {
        nativeNotifications.onAction(action)
    }

    /**
     * Specify that the notification should use the built-in dark styling,
     * rather than the default 'modena' notification style.
     */
    fun darkStyle() {
        nativeNotifications.darkStyle()
    }

    /** Specify that the close button in the top-right corner of the notification should not be shown. */
    fun hideCloseButton() {
        nativeNotifications.hideCloseButton()
    }

    /** Specify the actions that should be shown in the notification as buttons. */
    fun actions(vararg actions: Action) {
        nativeNotifications.action(*actions)
    }

    /**
     * Collapses all the current notifications into a single notification when the
     * number of notifications exceed the threshold limit. A value of zero will disable
     * the threshold behavior.
     */
    fun threshold(threshold: Int, thresholdNotifications: Notifications) {
        nativeNotifications.threshold(threshold, thresholdNotifications)
    }

    /** Alias of [NotificationsBuilder.threshold] with builder DSL. */
    fun threshold(threshold: Int, thresholdNotificationsBuilder: NotificationsBuilder.() -> Unit) {
        nativeNotifications.threshold(threshold, buildNotifications(thresholdNotificationsBuilder))
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/layout/HBoxTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.layout.HBox
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class HBoxTest : LayoutsTest<KtfxPane, HBox>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = hbox { }
    override fun KtfxPane.child2() = hbox()
    override fun KtfxPane.child3() = hbox { }

    override fun HBox.testDefaultValues() {
        assertEquals(0.0, spacing)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/NumberValueBindingFloat.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("NumberValueBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.DoubleBinding
import javafx.beans.binding.FloatBinding
import javafx.beans.binding.FloatExpression
import javafx.beans.value.ObservableFloatValue

/** @see FloatExpression.negate */
inline operator fun ObservableFloatValue.unaryMinus(): FloatBinding = Bindings.negate(this) as FloatBinding

/** @see FloatExpression.add */
inline operator fun ObservableFloatValue.plus(other: Double): DoubleBinding = Bindings.add(this, other)

/** @see FloatExpression.add */
inline operator fun Double.plus(other: ObservableFloatValue): DoubleBinding = Bindings.add(this, other)

/** @see FloatExpression.add */
inline operator fun ObservableFloatValue.plus(other: Float): FloatBinding = Bindings.add(this, other) as FloatBinding

/** @see FloatExpression.add */
inline operator fun Float.plus(other: ObservableFloatValue): FloatBinding = Bindings.add(this, other) as FloatBinding

/** @see FloatExpression.add */
inline operator fun ObservableFloatValue.plus(other: Long): FloatBinding = Bindings.add(this, other) as FloatBinding

/** @see FloatExpression.add */
inline operator fun Long.plus(other: ObservableFloatValue): FloatBinding = Bindings.add(this, other) as FloatBinding

/** @see FloatExpression.add */
inline operator fun ObservableFloatValue.plus(other: Int): FloatBinding = Bindings.add(this, other) as FloatBinding

/** @see FloatExpression.add */
inline operator fun Int.plus(other: ObservableFloatValue): FloatBinding = Bindings.add(this, other) as FloatBinding

/** @see FloatExpression.subtract */
inline operator fun ObservableFloatValue.minus(other: Double): DoubleBinding = Bindings.subtract(this, other)

/** @see FloatExpression.subtract */
inline operator fun Double.minus(other: ObservableFloatValue): DoubleBinding = Bindings.subtract(this, other)

/** @see FloatExpression.subtract */
inline operator fun ObservableFloatValue.minus(other: Float): FloatBinding =
    Bindings.subtract(this, other) as FloatBinding

/** @see FloatExpression.subtract */
inline operator fun Float.minus(other: ObservableFloatValue): FloatBinding =
    Bindings.subtract(this, other) as FloatBinding

/** @see FloatExpression.subtract */
inline operator fun ObservableFloatValue.minus(other: Long): FloatBinding =
    Bindings.subtract(this, other) as FloatBinding

/** @see FloatExpression.subtract */
inline operator fun Long.minus(other: ObservableFloatValue): FloatBinding =
    Bindings.subtract(this, other) as FloatBinding

/** @see FloatExpression.subtract */
inline operator fun ObservableFloatValue.minus(other: Int): FloatBinding =
    Bindings.subtract(this, other) as FloatBinding

/** @see FloatExpression.subtract */
inline operator fun Int.minus(other: ObservableFloatValue): FloatBinding =
    Bindings.subtract(this, other) as FloatBinding

/** @see FloatExpression.multiply */
inline operator fun ObservableFloatValue.times(other: Double): DoubleBinding = Bindings.multiply(this, other)

/** @see FloatExpression.multiply */
inline operator fun Double.times(other: ObservableFloatValue): DoubleBinding = Bindings.multiply(this, other)

/** @see FloatExpression.multiply */
inline operator fun ObservableFloatValue.times(other: Float): FloatBinding =
    Bindings.multiply(this, other) as FloatBinding

/** @see FloatExpression.multiply */
inline operator fun Float.times(other: ObservableFloatValue): FloatBinding =
    Bindings.multiply(this, other) as FloatBinding

/** @see FloatExpression.multiply */
inline operator fun ObservableFloatValue.times(other: Long): FloatBinding =
    Bindings.multiply(this, other) as FloatBinding

/** @see FloatExpression.multiply */
inline operator fun Long.times(other: ObservableFloatValue): FloatBinding =
    Bindings.multiply(this, other) as FloatBinding

/** @see FloatExpression.multiply */
inline operator fun ObservableFloatValue.times(other: Int): FloatBinding =
    Bindings.multiply(this, other) as FloatBinding

/** @see FloatExpression.multiply */
inline operator fun Int.times(other: ObservableFloatValue): FloatBinding =
    Bindings.multiply(this, other) as FloatBinding

/** @see FloatExpression.divide */
inline operator fun ObservableFloatValue.div(other: Double): DoubleBinding = Bindings.divide(this, other)

/** @see FloatExpression.divide */
inline operator fun Double.div(other: ObservableFloatValue): DoubleBinding = Bindings.divide(this, other)

/** @see FloatExpression.divide */
inline operator fun ObservableFloatValue.div(other: Float): FloatBinding = Bindings.divide(this, other) as FloatBinding

/** @see FloatExpression.divide */
inline operator fun Float.div(other: ObservableFloatValue): FloatBinding = Bindings.divide(this, other) as FloatBinding

/** @see FloatExpression.divide */
inline operator fun ObservableFloatValue.div(other: Long): FloatBinding = Bindings.divide(this, other) as FloatBinding

/** @see FloatExpression.divide */
inline operator fun Long.div(other: ObservableFloatValue): FloatBinding = Bindings.divide(this, other) as FloatBinding

/** @see FloatExpression.divide */
inline operator fun ObservableFloatValue.div(other: Int): FloatBinding = Bindings.divide(this, other) as FloatBinding

/** @see FloatExpression.divide */
inline operator fun Int.div(other: ObservableFloatValue): FloatBinding = Bindings.divide(this, other) as FloatBinding


<|start_filename|>ktfx-commons/src/ktfx/bindings/BindingsString.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("BindingsKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.Observable
import javafx.beans.binding.Bindings
import javafx.beans.binding.StringBinding
import javafx.beans.value.ObservableBooleanValue
import javafx.beans.value.ObservableDoubleValue
import javafx.beans.value.ObservableFloatValue
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableLongValue
import javafx.beans.value.ObservableObjectValue
import javafx.collections.ObservableList
import javafx.collections.ObservableMap
import javafx.collections.ObservableSet
import ktfx.collections.observableListOf
import ktfx.collections.toObservableList
import java.util.concurrent.Callable

/** Create a [StringBinding] with multiple [Observable] dependencies. */
inline fun stringBindingOf(vararg dependencies: Observable, noinline valueProvider: () -> String?): StringBinding =
    Bindings.createStringBinding(Callable(valueProvider), *dependencies)

/** Create a [StringBinding] with multiple [Observable] dependencies using collection. */
fun stringBindingOf(dependencies: Collection<Observable>, valueProvider: () -> String?): StringBinding =
    stringBindingOf(*dependencies.toTypedArray(), valueProvider = valueProvider)

/** Create an [StringBinding] with single [ObservableList] dependency. */
fun <E> ObservableList<E>.asString(valueProvider: (List<E>) -> String?): StringBinding =
    object : StringBinding() {
        override fun dispose(): Unit = unbind(this@asString)
        override fun computeValue(): String? = valueProvider(this@asString)
        override fun getDependencies(): ObservableList<*> = this@asString

        init {
            bind(this@asString)
        }
    }

/** Create an [StringBinding] with single [ObservableSet] dependency. */
fun <E> ObservableSet<E>.asString(valueProvider: (Set<E>) -> String?): StringBinding =
    object : StringBinding() {
        override fun dispose(): Unit = unbind(this@asString)
        override fun computeValue(): String? = valueProvider(this@asString)
        override fun getDependencies(): ObservableList<*> = this@asString.toObservableList()

        init {
            bind(this@asString)
        }
    }

/** Create an [StringBinding] with single [ObservableMap] dependency. */
fun <K, V> ObservableMap<K, V>.asString(valueProvider: (Map<K, V>) -> String?): StringBinding =
    object : StringBinding() {
        override fun dispose(): Unit = unbind(this@asString)
        override fun computeValue(): String? = valueProvider(this@asString)
        override fun getDependencies(): ObservableList<*> = this@asString.keys.toObservableList()

        init {
            bind(this@asString)
        }
    }

/** Create a [StringBinding] with single [ObservableObjectValue] dependency. */
fun <V> ObservableObjectValue<V>.asString(valueProvider: (V?) -> String?): StringBinding =
    object : StringBinding() {
        override fun dispose(): Unit = unbind(this@asString)
        override fun computeValue(): String? = valueProvider(this@asString.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asString)

        init {
            bind(this@asString)
        }
    }

/** Create a [StringBinding] with single [ObservableBooleanValue] dependency. */
fun ObservableBooleanValue.asString(valueProvider: (Boolean) -> String?): StringBinding =
    object : StringBinding() {
        override fun dispose(): Unit = unbind(this@asString)
        override fun computeValue(): String? = valueProvider(this@asString.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asString)

        init {
            bind(this@asString)
        }
    }

/** Create a [StringBinding] with single [ObservableDoubleValue] dependency. */
fun ObservableDoubleValue.asString(valueProvider: (Double) -> String?): StringBinding =
    object : StringBinding() {
        override fun dispose(): Unit = unbind(this@asString)
        override fun computeValue(): String? = valueProvider(this@asString.value as Double)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asString)

        init {
            bind(this@asString)
        }
    }

/** Create a [StringBinding] with single [ObservableFloatValue] dependency. */
fun ObservableFloatValue.asString(valueProvider: (Float) -> String?): StringBinding =
    object : StringBinding() {
        override fun dispose(): Unit = unbind(this@asString)
        override fun computeValue(): String? = valueProvider(this@asString.value as Float)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asString)

        init {
            bind(this@asString)
        }
    }

/** Create a [StringBinding] with single [ObservableIntegerValue] dependency. */
fun ObservableIntegerValue.asString(valueProvider: (Int) -> String?): StringBinding =
    object : StringBinding() {
        override fun dispose(): Unit = unbind(this@asString)
        override fun computeValue(): String? = valueProvider(this@asString.value as Int)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asString)

        init {
            bind(this@asString)
        }
    }

/** Create a [StringBinding] with single [ObservableLongValue] dependency. */
fun ObservableLongValue.asString(valueProvider: (Long) -> String?): StringBinding =
    object : StringBinding() {
        override fun dispose(): Unit = unbind(this@asString)
        override fun computeValue(): String? = valueProvider(this@asString.value as Long)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asString)

        init {
            bind(this@asString)
        }
    }


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_TableColumn.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.control.TableColumn
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see TableColumn.setOnEditStart
 */
public fun <S, T> TableColumn<S, T>.onEditStart(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(TableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditStart { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TableColumn.setOnEditCommit
 */
public fun <S, T> TableColumn<S, T>.onEditCommit(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(TableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditCommit { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TableColumn.setOnEditCancel
 */
public fun <S, T> TableColumn<S, T>.onEditCancel(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(TableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditCancel { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-commons/tests/src/ktfx/controls/GridConstraintsTest.kt<|end_filename|>
package ktfx.controls

import javafx.scene.layout.GridPane
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class GridConstraintsTest {

    @Test
    fun rowConstraints() {
        val gridPane = GridPane()
        gridPane.rowConstraints {
            append()
            append { isFillHeight = true }
        }
        assertEquals(2, gridPane.rowConstraints.size)
        assertTrue(gridPane.rowConstraints.last().isFillHeight)
    }

    @Test
    fun columnConstraints() {
        val gridPane = GridPane()
        gridPane.columnConstraints {
            append()
            append { prefWidth = 72.0 }
        }
        assertEquals(2, gridPane.columnConstraints.size)
        assertEquals(72.0, gridPane.columnConstraints.last().prefWidth)
    }
}

<|start_filename|>rulesets/basic/tests/src/com/hendraanggrian/ktfx/rules/NoGetterPropertyStaticImportRuleTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.pinterest.ktlint.core.Rule
import com.hendraanggrian.ktfx.test.RuleTest
import kotlin.test.Test

class NoGetterPropertyStaticImportRuleTest : RuleTest {
    override val rule: Rule = NoGetterPropertyStaticImportRule()

    @Test
    fun memberAndDeclaration() = assertRule(
        lintErrorOf(2, 17, "Annotation members should static import"),
        lintErrorOf(2, 82, "Declaration should static import")
    ) {
        """
            var myString: String
                @Deprecated(KtfxInternals.NO_GETTER, level = DeprecationLevel.ERROR) get() = KtfxInternals.noGetter()
                set(value) { }
        """
    }

    @Test
    fun member() = assertRule(
        lintErrorOf(2, 17, "Annotation members should static import")
    ) {
        """
            var myString: String
                @Deprecated(KtfxInternals.NO_GETTER, level = DeprecationLevel.ERROR) get() = noGetter()
                set(value) { }
        """
    }

    @Test
    fun declaration() = assertRule(
        lintErrorOf(2, 51, "Declaration should static import")
    ) {
        """
            var myString: String
                @Deprecated(NO_GETTER, level = ERROR) get() = KtfxInternals.noGetter()
                set(value) { }
        """
    }
}

<|start_filename|>ktfx-listeners/src/javafx/scene/Scene.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.scene.Scene
import javafx.scene.SnapshotResult
import javafx.scene.image.WritableImage

/** Registers an event filter to this scene. */
inline fun <E : Event> Scene.eventFilter(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventFilter(type, it) }

/** Registers an event handler to this scene. */
inline fun <E : Event> Scene.eventHandler(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventHandler(type, it) }

/** Takes a snapshot of this scene at the next frame and calls the specified callback method when the image is ready. */
inline fun Scene.capture(
    image: WritableImage? = null,
    noinline callback: (SnapshotResult) -> Unit
): Unit = snapshot({ callback(it); null }, image)


<|start_filename|>ktfx-commons/tests/src/ktfx/collections/ObservableCollectionsSetTest.kt<|end_filename|>
package ktfx.collections

import javafx.collections.ObservableSet
import com.hendraanggrian.ktfx.test.BaseCollectionsTest

class ObservableCollectionsSetTest : BaseCollectionsTest<ObservableSet<String>>() {

    override fun empty() = emptyObservableSet<String>()
    override fun of() = observableSetOf<String>()
    override fun of(value: String) = observableSetOf(value)
    override fun of(vararg values: String) = observableSetOf(*values)
    override fun mutableOf() = mutableObservableSetOf<String>()
    override fun mutableOf(vararg values: String) = mutableObservableSetOf(*values)

    override fun Array<String>.to() = toObservableSet()
    override fun List<String>.to() = toObservableSet()
    override fun Sequence<String>.to() = toObservableSet()
    override fun Array<String>.toMutable() = toMutableObservableSet()
    override fun List<String>.toMutable() = toMutableObservableSet()
    override fun Sequence<String>.toMutable() = toMutableObservableSet()
}


<|start_filename|>ktfx-commons/src/ktfx/controls/Borders.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controls

import javafx.geometry.Insets
import javafx.scene.image.Image
import javafx.scene.layout.Border
import javafx.scene.layout.BorderImage
import javafx.scene.layout.BorderRepeat
import javafx.scene.layout.BorderStroke
import javafx.scene.layout.BorderStrokeStyle
import javafx.scene.layout.BorderWidths
import javafx.scene.layout.CornerRadii
import javafx.scene.layout.Region
import javafx.scene.paint.Paint
import ktfx.internal.KtfxInternals.NO_GETTER
import ktfx.internal.KtfxInternals.noGetter
import kotlin.DeprecationLevel.ERROR

/**
 * Builds new border with multiple [BorderStroke] and/or [BorderImage].
 * @param builderAction populate newly created stroke and/or image.
 * @return created border.
 */
inline fun buildBorder(
    builderAction: BorderBuilder.() -> Unit
): Border = BorderBuilder().apply(builderAction).build()

/**
 * Sets new border with multiple [BorderStroke] and/or [BorderImage].
 * @param builderAction populate newly created stroke and/or image.
 * @return applied border.
 */
inline fun Region.border(
    noinline builderAction: BorderBuilder.() -> Unit
): Border = buildBorder(builderAction).also { border = it }

/**
 * Sets new border with single [BorderStroke].
 * @param builderAction stroke configurator.
 * @return applied border.
 */
inline fun Region.borderStroke(
    noinline builderAction: BorderBuilder.StrokeBuilder.() -> Unit
): Border = border { stroke(builderAction) }

/**
 * Sets new border with single [BorderImage].
 * @param builderAction image configurator.
 * @return applied border.
 */
inline fun Region.borderImage(
    image: Image,
    noinline builderAction: BorderBuilder.ImageBuilder.() -> Unit
): Border = border { image(image, builderAction) }

/** Border configurator class. */
class BorderBuilder {

    /** Current strokes within this border. */
    val strokes: MutableList<BorderStroke> = mutableListOf()

    /** Current images within this border. */
    val images: MutableList<BorderImage> = mutableListOf()

    /**
     * Append a [BorderStroke].
     * @param builderAction stroke configurator.
     * @return added stroke.
     */
    inline fun stroke(builderAction: StrokeBuilder.() -> Unit): BorderStroke =
        StrokeBuilder().apply(builderAction).build().also { strokes += it }

    /**
     * Append a [BorderImage].
     * @param builderAction image configurator.
     * @return added image.
     */
    inline fun image(image: Image, builderAction: ImageBuilder.() -> Unit): BorderImage =
        ImageBuilder(image).apply(builderAction).build().also { images += it }

    /** Return border based on current configuration. */
    fun build(): Border = Border(strokes, images)

    /** Border stroke configurator class. */
    class StrokeBuilder {
        /** The fill to use on the top. If null, defaults to [javafx.scene.paint.Color.BLACK]. */
        var topStroke: Paint? = null

        /** The fill to use on the right. If null, defaults to the same value as [topStroke]. */
        var rightStroke: Paint? = null

        /** The fill to use on the bottom. If null, defaults to the same value as [bottomStroke]. */
        var bottomStroke: Paint? = null

        /** The fill to use on the left. If null, defaults to the same value as [rightStroke]. */
        var leftStroke: Paint? = null

        /** The stroke to use for all sides. If null, we default to [javafx.scene.paint.Color.BLACK]. */
        var stroke: Paint?
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                topStroke = value
                rightStroke = value
                bottomStroke = value
                leftStroke = value
            }

        /** The style to use on the top. If null, defaults to [BorderStrokeStyle.NONE]. */
        var topStyle: BorderStrokeStyle? = null

        /** The style to use on the right. If null, defaults to the same value as [topStyle]. */
        var rightStyle: BorderStrokeStyle? = null

        /** The style to use on the bottom. If null, defaults to the same value as [topStyle]. */
        var bottomStyle: BorderStrokeStyle? = null

        /** The style to use on the left. If null, defaults to the same value as [rightStyle]. */
        var leftStyle: BorderStrokeStyle? = null

        /** The style to use for all sides. If null, we default to [BorderStrokeStyle.NONE]. */
        var style: BorderStrokeStyle?
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                topStyle = value
                rightStyle = value
                bottomStyle = value
                leftStyle = value
            }

        /** The radii. If null, we default to square corners by using [CornerRadii.EMPTY]. */
        var radii: CornerRadii? = null

        /** The thickness of each side. If null, we default to [BorderWidths.DEFAULT]. */
        var widths: BorderWidths? = null

        /** The insets indicating where to draw the border relative to the region edges. */
        var insets: Insets? = null

        /** Return border stroke based on current configuration. */
        fun build(): BorderStroke = BorderStroke(
            topStroke, rightStroke, bottomStroke, leftStroke,
            topStyle, rightStyle, bottomStyle, leftStyle,
            radii, widths, insets
        )
    }

    /** Border image configurator class. */
    class ImageBuilder(private val image: Image) {
        /** The widths of the border in each dimension. A null value results in [BorderWidths.EMPTY]. */
        var widths: BorderWidths? = null

        /** The insets at which to place the border relative to the region. A null value results in [Insets.EMPTY]. */
        var insets: Insets? = null

        /** The slices for the image. If null, defaults to [BorderWidths.DEFAULT]. */
        var slices: BorderWidths? = null

        var isFilled: Boolean = false

        /** The repeat value for the border image in the x direction. If null, defaults to [BorderRepeat.STRETCH]. */
        var repeatX: BorderRepeat? = null

        /** The repeat value for the border image in the y direction. If null, defaults to the same value as repeatX. */
        var repeatY: BorderRepeat? = null

        /** The repeat value for the border image in the x and y direction. If null, defaults to [BorderRepeat.STRETCH]. */
        var repeat: BorderRepeat?
            @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
            set(value) {
                repeatX = value
                repeatY = value
            }

        /** Return border image based on current configuration. */
        fun build(): BorderImage = BorderImage(image, widths, insets, slices, isFilled, repeatX, repeatY)
    }
}


<|start_filename|>thirdparty/jfoenix-coroutines/tests/src/com/jfoenix/transitions/JFXAnimationTimerTest.kt<|end_filename|>
package ktfx.jfoenix.coroutines

import com.jfoenix.transitions.JFXAnimationTimer
import kotlinx.coroutines.Dispatchers
import ktfx.jfoenix.test.BaseJFXAnimationTimerTest

class JFXAnimationTimerTest : BaseJFXAnimationTimerTest() {

    override fun JFXAnimationTimer.callOnFinished(action: () -> Unit) =
        onFinished(Dispatchers.Unconfined) { action() }
}

<|start_filename|>ktfx-layouts/src/javafx/scene/control/Tooltip.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.Control
import javafx.scene.control.Tab
import javafx.scene.control.Tooltip
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/** Create a [Tooltip] with configuration block. */
inline fun tooltip(
    text: String? = null,
    configuration: (@KtfxLayoutDslMarker Tooltip).() -> Unit
): Tooltip {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return Tooltip(text).apply(configuration)
}

/** Set a [Tooltip] to this [Node]. */
fun Node.tooltip(
    text: String? = null
): Tooltip = Tooltip(text).also { Tooltip.install(this, it) }

/** Set a [Tooltip] with configuration block to this [Node]. */
inline fun Node.tooltip(
    text: String? = null,
    configuration: (@KtfxLayoutDslMarker Tooltip).() -> Unit
): Tooltip {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return ktfx.layouts.tooltip(text, configuration).also { Tooltip.install(this, it) }
}

/** Set a [Tooltip] to this [Control]. */
fun Control.tooltip(
    text: String? = null
): Tooltip = Tooltip(text).also { tooltip = it }

/** Set a [Tooltip] with configuration block to this [Control]. */
inline fun Control.tooltip(
    text: String? = null,
    configuration: (@KtfxLayoutDslMarker Tooltip).() -> Unit
): Tooltip {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return ktfx.layouts.tooltip(text, configuration).also { tooltip = it }
}

/** Set a [Tooltip] to this [Tab]. */
fun Tab.tooltip(
    text: String? = null
): Tooltip = Tooltip(text).also { tooltip = it }

/** Set a [Tooltip] with configuration block to this [Tab]. */
inline fun Tab.tooltip(
    text: String? = null,
    configuration: (@KtfxLayoutDslMarker Tooltip).() -> Unit
): Tooltip {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return ktfx.layouts.tooltip(text, configuration).also { tooltip = it }
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Ellipse.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.Ellipse
import kotlin.Double
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add an [Ellipse] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.ellipse(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0
): Ellipse = ellipse(centerX = centerX, centerY = centerY, radiusX = radiusX, radiusY = radiusY) { }

/**
 * Create an [Ellipse] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun ellipse(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker Ellipse).() -> Unit
): Ellipse {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Ellipse(centerX, centerY, radiusX, radiusY)
    child.configuration()
    return child
}

/**
 * Add an [Ellipse] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.ellipse(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker Ellipse).() -> Unit
): Ellipse {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Ellipse(centerX, centerY, radiusX, radiusY)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Ellipse].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledEllipse(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): Ellipse = styledEllipse(
    centerX = centerX, centerY = centerY, radiusX = radiusX,
    radiusY =
    radiusY,
    styleClass = *styleClass, id = id
) { }

/**
 * Add a styled [Ellipse] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledEllipse(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): Ellipse = styledEllipse(
    centerX = centerX, centerY = centerY, radiusX = radiusX,
    radiusY =
    radiusY,
    styleClass = *styleClass, id = id
) { }

/**
 * Create a styled [Ellipse] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledEllipse(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Ellipse).() -> Unit
): Ellipse {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Ellipse(centerX, centerY, radiusX, radiusY)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Ellipse] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledEllipse(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Ellipse).() -> Unit
): Ellipse {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Ellipse(centerX, centerY, radiusX, radiusY)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/src/ktfx/dialogs/Dialog.kt<|end_filename|>
package ktfx.dialogs

import javafx.scene.control.Button
import javafx.scene.control.ButtonBar
import javafx.scene.control.ButtonType
import javafx.scene.control.Dialog
import javafx.scene.image.Image
import javafx.scene.image.ImageView
import ktfx.internal.KtfxInternals.NO_GETTER
import ktfx.internal.KtfxInternals.noGetter
import ktfx.windows.icon
import ktfx.windows.stage
import kotlin.DeprecationLevel.ERROR
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/** Removes old icons and set a new one to this dialog. */
inline var Dialog<*>.icon: Image
    @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
    set(value) {
        dialogPane.scene.stage.icon = value
    }

/** Apply [ImageView] as graphic and icon of this dialog. */
inline var Dialog<*>.graphicIcon: ImageView
    @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
    set(value) {
        graphic = value
        icon = value.image
    }

/** Apply string as header text and title of this dialog. */
inline var Dialog<*>.headerTitle: String
    @Deprecated(NO_GETTER, level = ERROR) get() = noGetter()
    set(value) {
        headerText = value
        title = value
    }

/** Returns button configurator of this [Dialog]. */
val Dialog<*>.buttons: DialogButtonContainer get() = DialogButtonContainer(this)

/**
 * Configure [Dialog] buttons.
 * @param configuration the configuration block.
 */
@OptIn(ExperimentalContracts::class)
fun Dialog<*>.buttons(configuration: DialogButtonContainerScope.() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    DialogButtonContainerScope(this).configuration()
}

/** Container of [ButtonType], providing sets of useful operation. */
open class DialogButtonContainer internal constructor(private val nativeDialog: Dialog<*>) {

    /** Add apply button. */
    fun apply(): Button = add(ButtonType.APPLY)

    /** Add apply button using [configuration] block. */
    inline fun apply(configuration: Button.() -> Unit): Button = add(ButtonType.APPLY).apply(configuration)

    /** Add ok button. */
    fun ok(): Button = add(ButtonType.OK)

    /** Add ok button using [configuration] block. */
    inline fun ok(configuration: Button.() -> Unit): Button = add(ButtonType.OK).apply(configuration)

    /** Add cancel button. */
    fun cancel(): Button = add(ButtonType.CANCEL)

    /** Add cancel button using [configuration] block. */
    inline fun cancel(configuration: Button.() -> Unit): Button = add(ButtonType.CANCEL).apply(configuration)

    /** Add close button. */
    fun close(): Button = add(ButtonType.CLOSE)

    /** Add close button using [configuration] block. */
    inline fun close(configuration: Button.() -> Unit): Button = add(ButtonType.CLOSE).apply(configuration)

    /** Add yes button. */
    fun yes(): Button = add(ButtonType.YES)

    /** Add yes button using [configuration] block. */
    inline fun yes(configuration: Button.() -> Unit): Button = add(ButtonType.YES).apply(configuration)

    /** Add no button. */
    fun no(): Button = add(ButtonType.NO)

    /** Add no button using [configuration] block. */
    inline fun no(configuration: Button.() -> Unit): Button = add(ButtonType.NO).apply(configuration)

    /** Add finish button. */
    fun finish(): Button = add(ButtonType.FINISH)

    /** Add finish button using [configuration] block. */
    inline fun finish(configuration: Button.() -> Unit): Button = add(ButtonType.FINISH).apply(configuration)

    /** Add next button. */
    fun next(): Button = add(ButtonType.NEXT)

    /** Add next button using [configuration] block. */
    inline fun next(configuration: Button.() -> Unit): Button = add(ButtonType.NEXT).apply(configuration)

    /** Add previous button. */
    fun previous(): Button = add(ButtonType.PREVIOUS)

    /** Add previous button using [configuration] block. */
    inline fun previous(configuration: Button.() -> Unit): Button = add(ButtonType.PREVIOUS).apply(configuration)

    /** Add custom button specifying [text] and [data]. */
    fun custom(
        text: String,
        data: ButtonBar.ButtonData = ButtonBar.ButtonData.OTHER
    ): Button = add(ButtonType(text, data))

    /** Add custom button specifying [text] and [data] using [configuration] block. */
    inline fun custom(
        text: String,
        data: ButtonBar.ButtonData = ButtonBar.ButtonData.OTHER,
        configuration: Button.() -> Unit
    ): Button = add(ButtonType(text, data)).apply(configuration)

    /** Add raw [ButtonType]. */
    fun add(type: ButtonType): Button {
        nativeDialog.dialogPane.buttonTypes += type
        return nativeDialog.dialogPane.lookupButton(type) as Button
    }

    /** Add raw [ButtonType] with Kotlin operator. */
    operator fun plusAssign(type: ButtonType) {
        add(type)
    }
}

/** Receiver for `buttons` block. */
class DialogButtonContainerScope internal constructor(nativeDialog: Dialog<*>) : DialogButtonContainer(nativeDialog) {

    /** Alias of [custom] with operator function. */
    inline operator fun String.invoke(
        data: ButtonBar.ButtonData = ButtonBar.ButtonData.OTHER,
        configuration: Button.() -> Unit
    ): Button = custom(this, data, configuration)
}


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_WebEngine.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.geometry.Rectangle2D
import javafx.scene.web.WebEngine
import javafx.scene.web.WebErrorEvent
import javafx.scene.web.WebEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Boolean
import kotlin.String
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see WebEngine.setOnAlert
 */
public fun WebEngine.onAlert(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WebEvent<String>) -> Unit
) {
    return setOnAlert { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see WebEngine.setOnStatusChanged
 */
public fun WebEngine.onStatusChanged(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WebEvent<String>) -> Unit
) {
    return setOnStatusChanged { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see WebEngine.setOnResized
 */
public fun WebEngine.onResized(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WebEvent<Rectangle2D>) -> Unit
) {
    return setOnResized { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see WebEngine.setOnVisibilityChanged
 */
public fun WebEngine.onVisibilityChanged(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(WebEvent<Boolean>) -> Unit
) {
    return setOnVisibilityChanged { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see WebEngine.setOnError
 */
public fun WebEngine.onError(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WebErrorEvent) -> Unit
) {
    return setOnError { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>testing/listeners-coroutines/src/com/hendraanggrian/ktfx/test/events/FakeKeyEvent.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.EventType
import javafx.scene.input.KeyCode
import javafx.scene.input.KeyEvent
import kotlin.test.assertEquals
import kotlin.test.assertFalse

/**
 * @receiver source of this fake event.
 */
fun Any.assertFakeKeyEvent(actual: KeyEvent, expectedType: EventType<KeyEvent>) {
    assertEquals(this, actual.source)
    assertEquals(FakeEventTarget, actual.target)
    assertEquals(expectedType, actual.eventType)
    // assertEquals("", actual.character) // unstable
    // assertEquals("Hello world", actual.text) // unstable
    // assertEquals(KeyCode.A, actual.code) // unstable
    assertFalse(actual.isShiftDown)
    assertFalse(actual.isControlDown)
    assertFalse(actual.isAltDown)
    assertFalse(actual.isMetaDown)
}

/**
 * @receiver source of this fake event.
 */
fun Any.fakeKeyEventOf(eventType: EventType<KeyEvent>) = KeyEvent(
    this, FakeEventTarget, eventType, "",
    "Hello world", KeyCode.A, false, false,
    false, false
)

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/ComboBoxBaseTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.ComboBoxBase
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseComboBoxBaseTest

class ComboBoxBaseTest : BaseComboBoxBaseTest() {

    override fun <E> ComboBoxBase<E>.callOnAction(action: (ActionEvent) -> Unit) =
        onAction(Dispatchers.Unconfined) { action(it) }

    override fun <E> ComboBoxBase<E>.callOnShowing(action: (Event) -> Unit) =
        onShowing(Dispatchers.Unconfined) { action(it) }

    override fun <E> ComboBoxBase<E>.callOnShown(action: (Event) -> Unit) =
        onShown(Dispatchers.Unconfined) { action(it) }

    override fun <E> ComboBoxBase<E>.callOnHiding(action: (Event) -> Unit) =
        onHiding(Dispatchers.Unconfined) { action(it) }

    override fun <E> ComboBoxBase<E>.callOnHidden(action: (Event) -> Unit) =
        onHidden(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/ConditionalBindingTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.booleanPropertyOf
import kotlin.test.Test
import kotlin.test.assertEquals

class ConditionalBindingTest {

    @Test
    fun given() {
        assertEquals(0, (given(booleanPropertyOf(false)) then 1 otherwise 0).value)
        assertEquals("Hello", (given(booleanPropertyOf(true)) then "Hello" otherwise "World").value)
    }
}


<|start_filename|>thirdparty/controlsfx-listeners/tests/src/org/controlsfx/control/PlusMinusSliderTest.kt<|end_filename|>
package ktfx.controlsfx.listeners

import ktfx.controlsfx.test.BasePlusMinusSliderTest
import org.controlsfx.control.PlusMinusSlider

class PlusMinusSliderTest : BasePlusMinusSliderTest() {

    override fun PlusMinusSlider.callOnValueChanged(action: (PlusMinusSlider.PlusMinusEvent) -> Unit) =
        onValueChanged(action)
}

<|start_filename|>thirdparty/jfoenix-listeners/tests/src/com/jfoenix/transitions/JFXAnimationTimerTest.kt<|end_filename|>
package ktfx.jfoenix.listeners

import com.jfoenix.transitions.JFXAnimationTimer
import ktfx.jfoenix.test.BaseJFXAnimationTimerTest

class JFXAnimationTimerTest : BaseJFXAnimationTimerTest() {

    override fun JFXAnimationTimer.callOnFinished(action: () -> Unit) = onFinished(action)
}

<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/listeners/ControlsFx.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.listeners

import com.hendraanggrian.kotlinpoet.parameterizedBy
import com.hendraanggrian.ktfx.codegen.T
import javafx.event.ActionEvent
import javafx.event.Event
import org.controlsfx.control.BreadCrumbBar
import org.controlsfx.control.HyperlinkLabel
import org.controlsfx.control.NotificationPane
import org.controlsfx.control.PlusMinusSlider

val ListenersFactory.Companion.ControlsFx: ListenersFactory
    get() = ListenersFactory(
        "thirdparty/controlsfx-listeners/src",
        "ktfx.controlsfx.listeners",
        "ControlsFxListenersKt",
    ).apply { initControlsFx() }

val CoroutinesFactory.Companion.ControlsFx: CoroutinesFactory
    get() = CoroutinesFactory(
        "thirdparty/controlsfx-coroutines/src",
        "ktfx.controlsfx.coroutines",
        "ControlsFxCoroutinesKt",
    ).apply { initControlsFx() }

fun BaseListenersFactory.initControlsFx() {
    // org.controlsfx.control
    (BreadCrumbBar::class.parameterizedBy(T)) {
        "setOnCrumbAction" { action(BreadCrumbBar.BreadCrumbActionEvent::class.parameterizedBy(T)) }
    }
    HyperlinkLabel::class { "setOnAction" { action<ActionEvent>() } }
    NotificationPane::class {
        "setOnShowing" { action<Event>() }
        "setOnShown" { action<Event>() }
        "setOnHiding" { action<Event>() }
        "setOnHidden" { action<Event>() }
    }
    PlusMinusSlider::class { "setOnValueChanged" { action<PlusMinusSlider.PlusMinusEvent>() } }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/ComparisonsBindingTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.intPropertyOf
import kotlin.test.Test
import kotlin.test.assertEquals

class ComparisonsBindingTest {

    @Test
    fun maxOf() {
        assertEquals(2, maxOf(intPropertyOf(1), intPropertyOf(2)).value)
        assertEquals(2.0, maxOf(intPropertyOf(1), 2.0).value)
        assertEquals(2.0, maxOf(2.0, intPropertyOf(1)).value)
        assertEquals(2f, maxOf(intPropertyOf(1), 2f).value)
        assertEquals(2f, maxOf(2f, intPropertyOf(1)).value)
        assertEquals(2L, maxOf(intPropertyOf(1), 2L).value)
        assertEquals(2L, maxOf(2L, intPropertyOf(1)).value)
        assertEquals(2, maxOf(intPropertyOf(1), 2).value)
        assertEquals(2, maxOf(2, intPropertyOf(1)).value)
    }

    @Test
    fun minOf() {
        assertEquals(1, minOf(intPropertyOf(1), intPropertyOf(2)).value)
        assertEquals(1.0, minOf(intPropertyOf(1), 2.0).value)
        assertEquals(1.0, minOf(2.0, intPropertyOf(1)).value)
        assertEquals(1f, minOf(intPropertyOf(1), 2f).value)
        assertEquals(1f, minOf(2f, intPropertyOf(1)).value)
        assertEquals(1L, minOf(intPropertyOf(1), 2L).value)
        assertEquals(1L, minOf(2L, intPropertyOf(1)).value)
        assertEquals(1, minOf(intPropertyOf(1), 2).value)
        assertEquals(1, minOf(2, intPropertyOf(1)).value)
    }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_QuadCurve.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.QuadCurve
import kotlin.Double
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [QuadCurve] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.quadCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX: Double = 0.0,
    controlY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0
): QuadCurve = quadCurve(
    startX = startX, startY = startY, controlX = controlX, controlY = controlY,
    endX = endX, endY = endY
) { }

/**
 * Create a [QuadCurve] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun quadCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX: Double = 0.0,
    controlY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker QuadCurve).() -> Unit
): QuadCurve {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = QuadCurve(startX, startY, controlX, controlY, endX, endY)
    child.configuration()
    return child
}

/**
 * Add a [QuadCurve] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.quadCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX: Double = 0.0,
    controlY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker QuadCurve).() -> Unit
): QuadCurve {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = QuadCurve(startX, startY, controlX, controlY, endX, endY)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [QuadCurve].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledQuadCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX: Double = 0.0,
    controlY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): QuadCurve = styledQuadCurve(
    startX = startX, startY = startY, controlX = controlX,
    controlY =
    controlY,
    endX = endX, endY = endY, styleClass = *styleClass, id = id
) { }

/**
 * Add a styled [QuadCurve] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledQuadCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX: Double = 0.0,
    controlY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): QuadCurve = styledQuadCurve(
    startX = startX, startY = startY, controlX = controlX,
    controlY =
    controlY,
    endX = endX, endY = endY, styleClass = *styleClass, id = id
) { }

/**
 * Create a styled [QuadCurve] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledQuadCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX: Double = 0.0,
    controlY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker QuadCurve).() -> Unit
): QuadCurve {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = QuadCurve(startX, startY, controlX, controlY, endX, endY)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [QuadCurve] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledQuadCurve(
    startX: Double = 0.0,
    startY: Double = 0.0,
    controlX: Double = 0.0,
    controlY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker QuadCurve).() -> Unit
): QuadCurve {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = QuadCurve(startX, startY, controlX, controlY, endX, endY)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/NumberValueBindingLongTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.longPropertyOf
import kotlin.test.Test
import kotlin.test.assertEquals

class NumberValueBindingLongTest {

    @Test
    fun unaryMinus() = assertEquals(-1L, (-longPropertyOf(1L)).value)

    @Test
    fun plus() {
        // observable long to double
        assertEquals(3.0, (longPropertyOf(1L) + 2.0).value)
        assertEquals(3.0, (2.0 + longPropertyOf(1L)).value)
        // observable long to float
        assertEquals(3f, (longPropertyOf(1L) + 2f).value)
        assertEquals(3f, (2f + longPropertyOf(1L)).value)
        // observable long to long
        assertEquals(3L, (longPropertyOf(1L) + 2L).value)
        assertEquals(3L, (2L + longPropertyOf(1L)).value)
        // observable long to int
        assertEquals(3L, (longPropertyOf(1L) + 2).value)
        assertEquals(3L, (2 + longPropertyOf(1L)).value)
    }

    @Test
    fun minus() {
        // observable long to double
        assertEquals(-1.0, (longPropertyOf(1L) - 2.0).value)
        assertEquals(1.0, (2.0 - longPropertyOf(1L)).value)
        // observable long to float
        assertEquals(-1f, (longPropertyOf(1L) - 2f).value)
        assertEquals(1f, (2f - longPropertyOf(1L)).value)
        // observable long to long
        assertEquals(-1L, (longPropertyOf(1L) - 2L).value)
        assertEquals(1L, (2L - longPropertyOf(1L)).value)
        // observable long to int
        assertEquals(-1L, (longPropertyOf(1L) - 2).value)
        assertEquals(1L, (2 - longPropertyOf(1L)).value)
    }

    @Test
    fun times() {
        // observable long to double
        assertEquals(2.0, (longPropertyOf(1L) * 2.0).value)
        assertEquals(2.0, (2.0 * longPropertyOf(1L)).value)
        // observable long to float
        assertEquals(2f, (longPropertyOf(1L) * 2f).value)
        assertEquals(2f, (2f * longPropertyOf(1L)).value)
        // observable long to long
        assertEquals(2L, (longPropertyOf(1L) * 2L).value)
        assertEquals(2L, (2L * longPropertyOf(1L)).value)
        // observable long to int
        assertEquals(2L, (longPropertyOf(1L) * 2).value)
        assertEquals(2L, (2 * longPropertyOf(1L)).value)
    }

    @Test
    fun div() {
        // observable long to double
        assertEquals(0.5, (longPropertyOf(1L) / 2.0).value)
        assertEquals(2.0, (2.0 / longPropertyOf(1L)).value)
        // observable long to float
        assertEquals(0.5f, (longPropertyOf(1L) / 2f).value)
        assertEquals(2f, (2f / longPropertyOf(1L)).value)
        // observable long to long
        assertEquals(0L, (longPropertyOf(1L) / 2L).value)
        assertEquals(2L, (2L / longPropertyOf(1L)).value)
        // observable long to int
        assertEquals(0L, (longPropertyOf(1L) / 2).value)
        assertEquals(2L, (2 / longPropertyOf(1L)).value)
    }
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/RatingTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.Rating
import kotlin.test.assertEquals

class RatingTest : LayoutsTest<KtfxPane, Rating>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = rating { }
    override fun KtfxPane.child2() = rating()
    override fun KtfxPane.child3() = rating { }

    override fun Rating.testDefaultValues() {
        assertEquals(5, max)
        assertEquals(2.0, rating)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/Application.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx

import javafx.application.Application
import javafx.application.HostServices

/** Launch a JavaFX application with reified type. */
inline fun <reified T : Application> launchApplication(vararg args: String): Unit =
    Application.launch(T::class.java, *args)

/**
 * Resolves the specified relative URI against the code base URI and returns the resolved URI.
 * @see HostServices.getCodeBase
 * @see HostServices.resolveURI
 */
inline fun HostServices.resolveCodeURI(rel: String): String = resolveURI(codeBase, rel)

/**
 * Resolves the specified relative URI against the document base URI and returns the resolved URI.
 * @see HostServices.getDocumentBase
 * @see HostServices.resolveURI
 */
inline fun HostServices.resolveDocumentURI(rel: String): String = resolveURI(documentBase, rel)


<|start_filename|>rulesets/layouts/src/com/hendraanggrian/ktfx/rules/LayoutsRuleSetProvider.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.pinterest.ktlint.core.RuleSet
import com.pinterest.ktlint.core.RuleSetProvider

class LayoutsRuleSetProvider : RuleSetProvider {

    override fun get() = RuleSet(
        "layouts-ruleset",
        OpenClassRule()
    )
}

<|start_filename|>ktfx-commons/src/ktfx/ValueAccessors.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx

import javafx.beans.value.ObservableBooleanValue
import javafx.beans.value.ObservableDoubleValue
import javafx.beans.value.ObservableFloatValue
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableLongValue
import javafx.beans.value.ObservableStringValue
import javafx.beans.value.ObservableValue
import javafx.beans.value.WritableBooleanValue
import javafx.beans.value.WritableDoubleValue
import javafx.beans.value.WritableFloatValue
import javafx.beans.value.WritableIntegerValue
import javafx.beans.value.WritableLongValue
import javafx.beans.value.WritableStringValue
import javafx.beans.value.WritableValue
import kotlin.reflect.KProperty

/** Delegated property of this read-only [V] value, use with `by` keyword. */
inline operator fun <V> ObservableValue<V>.getValue(
    thisRef: Any?,
    property: KProperty<*>
): V? = value

/** Delegated property of this writable [V] value, use with `by` keyword. */
inline operator fun <V> WritableValue<in V>.setValue(
    thisRef: Any?,
    property: KProperty<*>,
    value: V?
): Unit = setValue(value)

/** Delegated property of this read-only [String] value, use with `by` keyword. */
inline operator fun ObservableStringValue.getValue(
    thisRef: Any?,
    property: KProperty<*>
): String? = get()

/** Delegated property of this writable [String] value, use with `by` keyword. */
inline operator fun WritableStringValue.setValue(
    thisRef: Any?,
    property: KProperty<*>,
    value: String?
): Unit = set(value)

/** Delegated property of this read-only [Boolean] value, use with `by` keyword. */
inline operator fun ObservableBooleanValue.getValue(
    thisRef: Any?,
    property: KProperty<*>
): Boolean = get()

/** Delegated property of this writable [Boolean] value, use with `by` keyword. */
inline operator fun WritableBooleanValue.setValue(
    thisRef: Any?,
    property: KProperty<*>,
    value: Boolean
): Unit = set(value)

/** Delegated property of this read-only [Double] value, use with `by` keyword. */
inline operator fun ObservableDoubleValue.getValue(
    thisRef: Any?,
    property: KProperty<*>
): Double = get()

/** Delegated property of this writable [Double] value, use with `by` keyword. */
inline operator fun WritableDoubleValue.setValue(
    thisRef: Any?,
    property: KProperty<*>,
    value: Double
): Unit = set(value)

/** Delegated property of this read-only [Float] value, use with `by` keyword. */
inline operator fun ObservableFloatValue.getValue(
    thisRef: Any?,
    property: KProperty<*>
): Float = get()

/** Delegated property of this writable [Float] value, use with `by` keyword. */
inline operator fun WritableFloatValue.setValue(
    thisRef: Any?,
    property: KProperty<*>,
    value: Float
): Unit = set(value)

/** Delegated property of this read-only [Long] value, use with `by` keyword. */
inline operator fun ObservableLongValue.getValue(
    thisRef: Any?,
    property: KProperty<*>
): Long = get()

/** Delegated property of this writable [Long] value, use with `by` keyword. */
inline operator fun WritableLongValue.setValue(
    thisRef: Any?,
    property: KProperty<*>,
    value: Long
): Unit = set(value)

/** Delegated property of this read-only [Int] value, use with `by` keyword. */
inline operator fun ObservableIntegerValue.getValue(
    thisRef: Any?,
    property: KProperty<*>
): Int = get()

/** Delegated property of this writable [Int] value, use with `by` keyword. */
inline operator fun WritableIntegerValue.setValue(
    thisRef: Any?,
    property: KProperty<*>,
    value: Int
): Unit = set(value)


<|start_filename|>ktfx-layouts/src/javafx/scene/layout/KtfxGridPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.layouts

import javafx.geometry.HPos
import javafx.geometry.Insets
import javafx.geometry.VPos
import javafx.scene.Node
import javafx.scene.layout.GridPane
import javafx.scene.layout.Priority
import kotlin.contracts.ExperimentalContracts

/**
 * [GridPane] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxGridPane : GridPane(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { children += it }

    /** Children row index in this layout. */
    inline var Node.rowIndex: Int?
        @JvmName("getRowIndex2") get() = getRowIndex(this)
        @JvmName("setRowIndex2") set(value) = setRowIndex(this, value)

    /** Children column index in this layout. */
    inline var Node.columnIndex: Int?
        @JvmName("getColumnIndex2") get() = getColumnIndex(this)
        @JvmName("setColumnIndex2") set(value) = setColumnIndex(this, value)

    /** Children row span in this layout. */
    inline var Node.rowSpan: Int?
        @JvmName("getRowSpan2") get() = getRowSpan(this)
        @JvmName("setRowSpan2") set(value) = setRowSpan(this, value)

    /** Children column span in this layout. */
    inline var Node.columnSpan: Int?
        @JvmName("getColumnSpan2") get() = getColumnSpan(this)
        @JvmName("setColumnSpan2") set(value) = setColumnSpan(this, value)

    /** Configure [rowIndex] and [columnIndex] fluidly. */
    fun <C : Node> C.grid(row: Int = 0, col: Int = 0): C {
        rowIndex = row
        columnIndex = col
        return this
    }

    /** Configure [rowIndex], [rowSpan] and [columnIndex] fluidly. */
    fun <C : Node> C.grid(
        row: Pair<Int, Int>,
        col: Int = 0
    ): C {
        rowIndex = row.first
        rowSpan = row.second
        columnIndex = col
        return this
    }

    /** Configure [rowIndex], [columnIndex] and [columnSpan] fluidly. */
    fun <C : Node> C.grid(
        row: Int = 0,
        col: Pair<Int, Int>
    ): C {
        rowIndex = row
        columnIndex = col.first
        columnSpan = col.second
        return this
    }

    /** Configure [rowIndex], [rowSpan], [columnIndex] and [columnSpan] fluidly. */
    fun <C : Node> C.grid(
        row: Pair<Int, Int>,
        col: Pair<Int, Int>
    ): C {
        rowIndex = row.first
        rowSpan = row.second
        columnIndex = col.first
        columnSpan = col.second
        return this
    }

    /** Children horizontal alignment in this layout. */
    inline var Node.halignment: HPos?
        @JvmName("getHalignment2") get() = getHalignment(this)
        @JvmName("setHalignment2") set(value) = setHalignment(this, value)

    /** Children vertical alignment in this layout. */
    inline var Node.valignment: VPos?
        @JvmName("getValignment2") get() = getValignment(this)
        @JvmName("setValignment2") set(value) = setValignment(this, value)

    /** Configure [halignment] fluidly. */
    fun <C : Node> C.halign(hpos: HPos): C {
        halignment = hpos
        return this
    }

    /** Configure [valignment] fluidly. */
    fun <C : Node> C.valign(vpos: VPos): C {
        valignment = vpos
        return this
    }

    /** Children fill width property in this layout. */
    inline var Node.isFillWidth: Boolean?
        @JvmName("isFillWidth2") get() = isFillWidth(this)
        @JvmName("setFillWidth2") set(value) = setFillWidth(this, value)

    /** Children fill height property in this layout. */
    inline var Node.isFillHeight: Boolean?
        @JvmName("isFillHeight2") get() = isFillHeight(this)
        @JvmName("setFillHeight2") set(value) = setFillHeight(this, value)

    /** Configure [isFillWidth] fluidly. */
    fun <C : Node> C.fillWidth(fill: Boolean = true): C {
        isFillWidth = fill
        return this
    }

    /** Configure [isFillHeight] fluidly. */
    fun <C : Node> C.fillHeight(fill: Boolean = true): C {
        isFillHeight = fill
        return this
    }

    /** Children horizontal grow priority in this layout. */
    inline var Node.hgrow: Priority?
        @JvmName("getHgrow2") get() = getHgrow(this)
        @JvmName("setHgrow2") set(value) = setHgrow(this, value)

    /** Children vertical grow priority in this layout. */
    inline var Node.vgrow: Priority?
        @JvmName("getVgrow2") get() = getVgrow(this)
        @JvmName("setVgrow2") set(value) = setVgrow(this, value)

    /** Configure [hgrow] fluidly. */
    fun <C : Node> C.hgrow(always: Boolean = true): C {
        hgrow = if (always) Priority.ALWAYS else Priority.NEVER
        return this
    }

    /** Configure [vgrow] fluidly. */
    fun <C : Node> C.vgrow(always: Boolean = true): C {
        vgrow = if (always) Priority.ALWAYS else Priority.NEVER
        return this
    }

    /** Children margin in this layout. */
    inline var Node.margin: Insets?
        @JvmName("getMargin2") get() = getMargin(this)
        @JvmName("setMargin2") set(value) = setMargin(this, value)

    /** Configure [margin] fluidly. */
    fun <C : Node> C.margin(insets: Insets): C {
        margin = insets
        return this
    }

    /** Clear children constraints. */
    @JvmName("clearConstraints2")
    inline fun Node.clearConstraints(): Unit = clearConstraints(this)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/inputs/KeyCombinationTest.kt<|end_filename|>
package ktfx.inputs

import javafx.scene.input.KeyCode
import javafx.scene.input.KeyCombination
import kotlin.test.Test
import kotlin.test.assertEquals

class KeyCombinationTest {

    @Test
    fun plus() {
        val charCombination = KeyCombination.SHIFT_DOWN + "x"
        assertEquals("x", charCombination.character)
        assertEquals(KeyCombination.ModifierValue.DOWN, charCombination.shift)

        val codeCombination1 = KeyCombination.ALT_DOWN + KeyCode.F
        assertEquals(KeyCode.F, codeCombination1.code)
        assertEquals(KeyCombination.ModifierValue.DOWN, codeCombination1.alt)

        val codeCombination2 = KeyCode.J + KeyCombination.CONTROL_DOWN
        assertEquals(KeyCode.J, codeCombination2.code)
        assertEquals(KeyCombination.ModifierValue.DOWN, codeCombination2.control)
    }
}


<|start_filename|>rulesets/layouts/src/com/hendraanggrian/ktfx/rules/OpenClassRule.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.pinterest.ktlint.core.Rule
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtDeclarationModifierList
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes

/** Top-level classes must remain open. */
class OpenClassRule : Rule("open-class") {

    override fun visit(node: ASTNode, autoCorrect: Boolean, emit: (Int, String, Boolean) -> Unit) {
        if (node.elementType != KtStubElementTypes.CLASS) {
            return
        }
        val ktClass = node.getPsi(KtClass::class.java)

        // only check top-level class
        if (ktClass.parent !is KtFile || ktClass.isInterface() || ktClass.isAnnotation()) {
            return
        }

        val modifierListNode = node.findChildByType(KtStubElementTypes.MODIFIER_LIST)
        val classKeywordNode = node.findChildByType(KtTokens.CLASS_KEYWORD)!!
        when (modifierListNode) {
            null -> emit(classKeywordNode.startOffset, "Empty modifiers, need open.", false)
            else -> {
                val ktModifierList = modifierListNode.getPsi(KtDeclarationModifierList::class.java)
                if (!ktModifierList.hasModifier(KtTokens.OPEN_KEYWORD) &&
                    !ktModifierList.hasModifier(KtTokens.PRIVATE_KEYWORD) &&
                    !ktModifierList.hasModifier(KtTokens.INTERNAL_KEYWORD)
                ) {
                    emit(classKeywordNode.startOffset, "Public classes need open modifier.", false)
                }
            }
        }
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ScrollPaneTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.ScrollPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class ScrollPaneTest : LayoutsTest<KtfxPane, ScrollPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = scrollPane { }
    override fun KtfxPane.child2() = scrollPane()
    override fun KtfxPane.child3() = scrollPane { }

    override fun ScrollPane.testDefaultValues() {
        assertNull(content)
    }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_ScrollBar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.ScrollBar
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [ScrollBar] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.scrollBar(): ScrollBar = scrollBar() { }

/**
 * Create a [ScrollBar] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun scrollBar(configuration: (@KtfxLayoutDslMarker ScrollBar).() -> Unit): ScrollBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ScrollBar()
    child.configuration()
    return child
}

/**
 * Add a [ScrollBar] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.scrollBar(configuration: (@KtfxLayoutDslMarker ScrollBar).() -> Unit):
    ScrollBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ScrollBar()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [ScrollBar].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledScrollBar(vararg styleClass: String, id: String? = null): ScrollBar =
    styledScrollBar(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [ScrollBar] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledScrollBar(vararg styleClass: String, id: String? = null): ScrollBar =
    styledScrollBar(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [ScrollBar] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledScrollBar(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker ScrollBar).() -> Unit
): ScrollBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ScrollBar()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [ScrollBar] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledScrollBar(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker ScrollBar).() -> Unit
): ScrollBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ScrollBar()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-layouts/src/com/jfoenix/controls/JFXToolbar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXToolbar
import ktfx.layouts.KtfxLayoutDslMarker
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
 * Configure [JFXToolbar] left items.
 * @param configuration the configuration block.
 */
inline fun JFXToolbar.leftItems(configuration: (@KtfxLayoutDslMarker KtfxJFXToolbar.HBoxConstraints).() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    KtfxJFXToolbar.HBoxConstraints(leftItems).configuration()
}

/**
 * Configure [JFXToolbar] right items.
 * @param configuration the configuration block.
 */
inline fun JFXToolbar.rightItems(configuration: (@KtfxLayoutDslMarker KtfxJFXToolbar.HBoxConstraints).() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    KtfxJFXToolbar.HBoxConstraints(rightItems).configuration()
}


<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/controls/DecoratorTest.kt<|end_filename|>
package ktfx.controlsfx.controls

import com.hendraanggrian.ktfx.test.initToolkit
import javafx.scene.Node
import javafx.scene.control.Button
import javafx.scene.control.Hyperlink
import javafx.scene.control.Label
import org.controlsfx.control.decoration.Decorator
import org.controlsfx.control.decoration.GraphicDecoration
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class DecoratorTest {
    private lateinit var node: Node

    @BeforeTest
    fun start() {
        initToolkit()
        node = Label("Hello world")
    }

    @Test
    fun addDecoration() {
        val decoration = GraphicDecoration(Button())
        node.addDecoration(decoration)
        assertEquals(1, node.decorations.size)
    }

    @Test
    fun removeDecoration() {
        val decoration1 = GraphicDecoration(Button())
        val decoration2 = GraphicDecoration(Hyperlink())
        node.addDecoration(decoration1)
        node.addDecoration(decoration2)
        node.removeDecoration(decoration1)
        assertEquals(decoration2, node.decorations.single())
    }

    @Test
    fun clearDecorations() {
        node.addDecoration(GraphicDecoration(Button()))
        node.addDecoration(GraphicDecoration(Hyperlink()))
        node.clearDecorations()
        assertNull(Decorator.getDecorations(node))
    }

    @Test
    fun decorations() {
        node.addDecoration(GraphicDecoration(Button()))
        node.addDecoration(GraphicDecoration(Hyperlink()))
        assertEquals(Decorator.getDecorations(node), node.decorations)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/MenuTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.Menu
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals
import kotlin.test.assertNull

class MenuTest : LayoutsTest<KtfxMenu, Menu>() {

    override fun manager() = KtfxMenu("", null)
    override fun KtfxMenu.childCount() = items.size
    override fun child1() = menu { }
    override fun KtfxMenu.child2() = menu()
    override fun KtfxMenu.child3() = menu { }

    override fun Menu.testDefaultValues() {
        assertEquals("", text)
        assertNull(graphic)
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/GridViewTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import com.google.common.truth.Truth.assertThat
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.GridView

class GridViewTest : LayoutsTest<KtfxPane, GridView<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = gridView<String> { }
    override fun KtfxPane.child2() = gridView<String>()
    override fun KtfxPane.child3() = gridView<String> { }

    override fun GridView<String>.testDefaultValues() {
        assertThat(items).isEmpty()
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXClippedPaneTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXClippedPane
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXClippedPaneTest : LayoutsTest<KtfxPane, JFXClippedPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxClippedPane { }
    override fun KtfxPane.child2() = jfxClippedPane()
    override fun KtfxPane.child3() = jfxClippedPane { }
}

<|start_filename|>ktfx-commons/src/ktfx/print/Printer.kt<|end_filename|>
package ktfx.print

import javafx.print.JobSettings
import javafx.print.Printer
import javafx.print.PrinterJob

/** Create a new printer job with specified job settings. */
inline fun Printer.createJob(
    settingsAction: JobSettings.() -> Unit = {
        copies = 1
        setPageRanges(1 untilPage 1)
    }
): PrinterJob = PrinterJob.createPrinterJob(this).also { it.jobSettings.settingsAction() }


<|start_filename|>testing/listeners-coroutines/src/com/hendraanggrian/ktfx/test/FakeEventTarget.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.EventDispatchChain
import javafx.event.EventTarget

object FakeEventTarget : EventTarget {

    override fun buildEventDispatchChain(tail: EventDispatchChain) = throw UnsupportedOperationException()
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/media/MediaPlayerTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.media.MediaMarkerEvent
import javafx.scene.media.MediaPlayer
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseMediaPlayerTest
import kotlin.test.Ignore

@Ignore
class MediaPlayerTest : BaseMediaPlayerTest() {

    override fun MediaPlayer.callOnError(action: () -> Unit) =
        onError(Dispatchers.Unconfined) { action() }

    override fun MediaPlayer.callOnMarker(action: (MediaMarkerEvent) -> Unit) =
        onMarker(Dispatchers.Unconfined) { action(it) }

    override fun MediaPlayer.callOnEndOfMedia(action: () -> Unit) =
        onEndOfMedia(Dispatchers.Unconfined) { action() }

    override fun MediaPlayer.callOnReady(action: () -> Unit) =
        onReady(Dispatchers.Unconfined) { action() }

    override fun MediaPlayer.callOnPlaying(action: () -> Unit) =
        onPlaying(Dispatchers.Unconfined) { action() }

    override fun MediaPlayer.callOnPaused(action: () -> Unit) =
        onPaused(Dispatchers.Unconfined) { action() }

    override fun MediaPlayer.callOnStopped(action: () -> Unit) =
        onStopped(Dispatchers.Unconfined) { action() }

    override fun MediaPlayer.callOnHalted(action: () -> Unit) =
        onHalted(Dispatchers.Unconfined) { action() }

    override fun MediaPlayer.callOnRepeat(action: () -> Unit) =
        onRepeat(Dispatchers.Unconfined) { action() }

    override fun MediaPlayer.callOnStalled(action: () -> Unit) =
        onStalled(Dispatchers.Unconfined) { action() }
}

<|start_filename|>rulesets/basic/src/com/hendraanggrian/ktfx/rules/BasicRuleSetProvider.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.pinterest.ktlint.core.RuleSet
import com.pinterest.ktlint.core.RuleSetProvider

class BasicRuleSetProvider : RuleSetProvider {

    override fun get() = RuleSet(
        "basic-ruleset",
        ExpressionFunctionReturnTypeRule(),
        NoGetterPropertyStaticImportRule(),
        NotNullAssertionOperatorRule()
    )
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseTreeViewTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.TreeItem
import javafx.scene.control.TreeView
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseTreeViewTest {
    private lateinit var tree: TreeView<String>

    abstract fun <E> TreeView<E>.callOnEditStart(action: (TreeView.EditEvent<E>) -> Unit)
    abstract fun <E> TreeView<E>.callOnEditCommit(action: (TreeView.EditEvent<E>) -> Unit)
    abstract fun <E> TreeView<E>.callOnEditCancel(action: (TreeView.EditEvent<E>) -> Unit)
    abstract fun <E> TreeView<E>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        tree = TreeView()
        tree.root = TreeItem()
    }

    @Test
    fun onEditStart() {
        tree.callOnEditStart {
            assertEquals(tree, it.source)
            assertEquals(TreeView.editStartEvent<String>(), it.eventType)
            assertEquals(tree.root, it.treeItem)
            assertEquals("", it.oldValue)
            assertEquals("", it.newValue)
        }
        tree.onEditStart.handle(TreeView.EditEvent(tree, TreeView.editStartEvent<String>(), tree.root, "", ""))
    }

    @Test
    fun onEditCommit() {
        tree.callOnEditCommit {
            assertEquals(tree, it.source)
            assertEquals(TreeView.editCommitEvent<String>(), it.eventType)
            assertEquals(tree.root, it.treeItem)
            assertEquals("", it.oldValue)
            assertEquals("", it.newValue)
        }
        tree.onEditCommit.handle(TreeView.EditEvent(tree, TreeView.editCommitEvent<String>(), tree.root, "", ""))
    }

    @Test
    fun onEditCancel() {
        tree.callOnEditCancel {
            assertEquals(tree, it.source)
            assertEquals(TreeView.editCancelEvent<String>(), it.eventType)
            assertEquals(tree.root, it.treeItem)
            assertEquals("", it.oldValue)
            assertEquals("", it.newValue)
        }
        tree.onEditCancel.handle(TreeView.EditEvent(tree, TreeView.editCancelEvent<String>(), tree.root, "", ""))
    }

    @Test
    fun onScrollTo() {
        tree.callOnScrollTo {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(ScrollToEvent.scrollToTopIndex(), it.eventType)
            assertEquals(0, it.scrollTarget)
        }
        tree.onScrollTo.handle(ScrollToEvent(this, FakeEventTarget, ScrollToEvent.scrollToTopIndex(), 0))
    }
}

<|start_filename|>ktfx/build.gradle.kts<|end_filename|>
group = RELEASE_GROUP
version = RELEASE_VERSION

plugins {
    kotlin("jvm")
    `maven-publish`
    signing
}

dependencies {
    api(project(":$RELEASE_ARTIFACT-commons"))
    api(project(":$RELEASE_ARTIFACT-layouts"))
    api(project(":$RELEASE_ARTIFACT-listeners"))
    api(project(":$RELEASE_ARTIFACT-coroutines"))
}

mavenPublishJvm()

<|start_filename|>ktfx-listeners/tests/src/javafx/collections/ObservableMapTest.kt<|end_filename|>
package ktfx.listeners

import javafx.collections.MapChangeListener
import javafx.collections.ObservableMap
import com.hendraanggrian.ktfx.test.BaseObservableMapTest

class ObservableMapTest : BaseObservableMapTest() {

    override fun <K, V> ObservableMap<K, V>.callListener(action: (MapChangeListener.Change<out K, out V>) -> Unit) {
        listener(action)
    }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/text/TextFlowTest.kt<|end_filename|>
package ktfx.text

import javafx.scene.text.Text
import javafx.scene.text.TextFlow
import kotlin.test.Test
import kotlin.test.assertEquals

class TextFlowTest {

    @Test
    fun append() {
        assertEquals(
            "I have 3 little piggies",
            TextFlow().append("I have ").append(3).append(" little piggies").text
        )
        assertEquals(
            StringBuilder().append("Here is ")
                .append(null as String?)
                .append(" String and ")
                .append(null as Any?)
                .append(" Object").toString(),
            TextFlow().append("Here is ")
                .append(null as String?)
                .append(" String and ")
                .append(null as Any?)
                .append(" Object").text
        )
    }

    @Test
    fun appendLine() {
        assertEquals(
            """
               A wolf just ate
               2
               of them
            """.trimIndent(),
            TextFlow().appendLine("A wolf just ate").appendLine(2).append("of them").text
        )
        assertEquals(
            StringBuilder().appendLine("Here is ")
                .appendLine(null as String?)
                .appendLine(" String and ")
                .appendLine(null as Any?)
                .appendLine(" Object").toString(),
            TextFlow().appendLine("Here is ")
                .appendLine(null as String?)
                .appendLine(" String and ")
                .appendLine(null as Any?)
                .appendLine(" Object").text
        )
    }

    private val TextFlow.text: String get() = children.joinToString("") { (it as Text).text }
}


<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/NumberValueBindingTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.intPropertyOf
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

/** Most of these tests avoid double, since they have their own tests. */
class NumberValueBindingTest {

    @Test
    fun plus() = assertEquals(3, (intPropertyOf(1) + intPropertyOf(2)).value)

    @Test
    fun minus() = assertEquals(-1, (intPropertyOf(1) - intPropertyOf(2)).value)

    @Test
    fun times() = assertEquals(2, (intPropertyOf(1) * intPropertyOf(2)).value)

    @Test
    fun div() = assertEquals(0, (intPropertyOf(1) / intPropertyOf(2)).value)

    @Test
    fun eq() {
        // observable number to observable number
        assertTrue((intPropertyOf(0) eq intPropertyOf(0)).value)
        assertTrue((intPropertyOf(0).eq(intPropertyOf(0), 0.0)).value)
        // observable number to double
        assertTrue((0.0 eq intPropertyOf(0)).value)
        assertTrue((0.0.eq(intPropertyOf(0), 0.0)).value)
        assertTrue((intPropertyOf(0) eq 0.0).value)
        assertTrue((intPropertyOf(0).eq(0.0, 0.0)).value)
        // observable number to float
        assertTrue((0f eq intPropertyOf(0)).value)
        assertTrue((0f.eq(intPropertyOf(0), 0.0)).value)
        assertTrue((intPropertyOf(0) eq 0f).value)
        assertTrue((intPropertyOf(0).eq(0f, 0.0)).value)
        // observable number to long
        assertTrue((0L eq intPropertyOf(0)).value)
        assertTrue((0L.eq(intPropertyOf(0), 0.0)).value)
        assertTrue((intPropertyOf(0) eq 0L).value)
        assertTrue((intPropertyOf(0).eq(0L, 0.0)).value)
        // observable number to int
        assertTrue((0 eq intPropertyOf(0)).value)
        assertTrue((0.eq(intPropertyOf(0), 0.0)).value)
        assertTrue((intPropertyOf(0) eq 0).value)
        assertTrue((intPropertyOf(0).eq(0, 0.0)).value)
    }

    @Test
    fun neq() {
        // observable number to observable number
        assertFalse((intPropertyOf(0) neq intPropertyOf(0)).value)
        assertFalse((intPropertyOf(0).neq(intPropertyOf(0), 0.0)).value)
        // observable number to double
        assertFalse((0.0 neq intPropertyOf(0)).value)
        assertFalse((0.0.neq(intPropertyOf(0), 0.0)).value)
        assertFalse((intPropertyOf(0) neq 0.0).value)
        assertFalse((intPropertyOf(0).neq(0.0, 0.0)).value)
        // observable number to float
        assertFalse((0f neq intPropertyOf(0)).value)
        assertFalse((0f.neq(intPropertyOf(0), 0.0)).value)
        assertFalse((intPropertyOf(0) neq 0f).value)
        assertFalse((intPropertyOf(0).neq(0f, 0.0)).value)
        // observable number to long
        assertFalse((0L neq intPropertyOf(0)).value)
        assertFalse((0L.neq(intPropertyOf(0), 0.0)).value)
        assertFalse((intPropertyOf(0) neq 0L).value)
        assertFalse((intPropertyOf(0).neq(0L, 0.0)).value)
        // observable number to int
        assertFalse((0 neq intPropertyOf(0)).value)
        assertFalse((0.neq(intPropertyOf(0), 0.0)).value)
        assertFalse((intPropertyOf(0) neq 0).value)
        assertFalse((intPropertyOf(0).neq(0, 0.0)).value)
    }

    @Test
    fun greater() {
        // observable number to observable number
        assertFalse((intPropertyOf(0) greater intPropertyOf(1)).value)
        // observable number to double
        assertFalse((0.0 greater intPropertyOf(1)).value)
        assertTrue((intPropertyOf(1) greater 0.0).value)
        // observable number to float
        assertFalse((0f greater intPropertyOf(1)).value)
        assertTrue((intPropertyOf(1) greater 0f).value)
        // observable number to long
        assertFalse((0L greater intPropertyOf(1)).value)
        assertTrue((intPropertyOf(1) greater 0L).value)
        // observable number to int
        assertFalse((0 greater intPropertyOf(1)).value)
        assertTrue((intPropertyOf(1) greater 0).value)
    }

    @Test
    fun less() {
        // observable number to observable number
        assertTrue((intPropertyOf(0) less intPropertyOf(1)).value)
        // observable number to double
        assertTrue((0.0 less intPropertyOf(1)).value)
        assertFalse((intPropertyOf(1) less 0.0).value)
        // observable number to float
        assertTrue((0f less intPropertyOf(1)).value)
        assertFalse((intPropertyOf(1) less 0f).value)
        // observable number to long
        assertTrue((0L less intPropertyOf(1)).value)
        assertFalse((intPropertyOf(1) less 0L).value)
        // observable number to int
        assertTrue((0 less intPropertyOf(1)).value)
        assertFalse((intPropertyOf(1) less 0).value)
    }

    @Test
    fun greaterEq() {
        // observable number to observable number
        assertTrue((intPropertyOf(0) greaterEq intPropertyOf(0)).value)
        // observable number to double
        assertTrue((0.0 greaterEq intPropertyOf(0)).value)
        assertTrue((intPropertyOf(0) greaterEq 0.0).value)
        // observable number to float
        assertTrue((0f greaterEq intPropertyOf(0)).value)
        assertTrue((intPropertyOf(0) greaterEq 0f).value)
        // observable number to long
        assertTrue((0L greaterEq intPropertyOf(0)).value)
        assertTrue((intPropertyOf(0) greaterEq 0L).value)
        // observable number to int
        assertTrue((0 greaterEq intPropertyOf(0)).value)
        assertTrue((intPropertyOf(0) greaterEq 0).value)
    }

    @Test
    fun lessEq() {
        // observable number to observable number
        assertTrue((intPropertyOf(0) lessEq intPropertyOf(0)).value)
        // observable number to double
        assertTrue((0.0 lessEq intPropertyOf(0)).value)
        assertTrue((intPropertyOf(0) lessEq 0.0).value)
        // observable number to float
        assertTrue((0f lessEq intPropertyOf(0)).value)
        assertTrue((intPropertyOf(0) lessEq 0f).value)
        // observable number to long
        assertTrue((0L lessEq intPropertyOf(0)).value)
        assertTrue((intPropertyOf(0) lessEq 0L).value)
        // observable number to int
        assertTrue((0 lessEq intPropertyOf(0)).value)
        assertTrue((intPropertyOf(0) lessEq 0).value)
    }
}


<|start_filename|>testing/layouts/build.gradle.kts<|end_filename|>
plugins {
    kotlin("jvm")
}

sourceSets {
    main {
        java.srcDir("src")
    }
}

dependencies {
    api(project(":testing:core"))
}

<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXTimePicker.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTimePicker
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import java.time.LocalTime
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXTimePicker] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.jfxTimePicker(time: LocalTime? = null): JFXTimePicker = jfxTimePicker(
    time =
    time
) { }

/**
 * Create a [JFXTimePicker] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun jfxTimePicker(
    time: LocalTime? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        JFXTimePicker
    ).() -> Unit
): JFXTimePicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXTimePicker(time)
    child.configuration()
    return child
}

/**
 * Add a [JFXTimePicker] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.jfxTimePicker(
    time: LocalTime? = null,
    configuration: (@KtfxLayoutDslMarker JFXTimePicker).() -> Unit
): JFXTimePicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXTimePicker(time)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXTimePicker].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledJFXTimePicker(
    time: LocalTime? = null,
    vararg styleClass: String,
    id: String? = null
): JFXTimePicker = styledJFXTimePicker(time = time, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXTimePicker] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledJFXTimePicker(
    time: LocalTime? = null,
    vararg styleClass: String,
    id: String? = null
): JFXTimePicker = styledJFXTimePicker(time = time, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [JFXTimePicker] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledJFXTimePicker(
    time: LocalTime? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXTimePicker).() -> Unit
): JFXTimePicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXTimePicker(time)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXTimePicker] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledJFXTimePicker(
    time: LocalTime? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXTimePicker).() -> Unit
): JFXTimePicker {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXTimePicker(time)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix/build.gradle.kts<|end_filename|>
group = RELEASE_GROUP
version = RELEASE_VERSION

plugins {
    kotlin("jvm")
    `maven-publish`
    signing
}

dependencies {
    api(project(":thirdparty:jfoenix-commons"))
    api(project(":thirdparty:jfoenix-layouts"))
    api(project(":thirdparty:jfoenix-listeners"))
    api(project(":thirdparty:jfoenix-coroutines"))
}

mavenPublishJvm("jfoenix")

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/RadioMenuItemTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.RadioMenuItem
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class RadioMenuItemTest : LayoutsTest<KtfxMenu, RadioMenuItem>() {

    override fun manager() = KtfxMenu("", null)
    override fun KtfxMenu.childCount() = items.size
    override fun child1() = radioMenuItem { }
    override fun KtfxMenu.child2() = radioMenuItem()
    override fun KtfxMenu.child3() = radioMenuItem { }

    override fun RadioMenuItem.testDefaultValues() {
        assertNull(text)
        assertNull(graphic)
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/concurrent/BaseServiceTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.concurrent.Service
import javafx.concurrent.WorkerStateEvent
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseServiceTest {

    class HelloWorldService : Service<String>() {
        override fun createTask() = BaseTaskTest.HelloWorldTask()
    }

    private val service = HelloWorldService()

    abstract fun <E> Service<E>.callOnReady(action: (WorkerStateEvent) -> Unit)
    abstract fun <E> Service<E>.callOnScheduled(action: (WorkerStateEvent) -> Unit)
    abstract fun <E> Service<E>.callOnRunning(action: (WorkerStateEvent) -> Unit)
    abstract fun <E> Service<E>.callOnSucceeded(action: (WorkerStateEvent) -> Unit)
    abstract fun <E> Service<E>.callOnCancelled(action: (WorkerStateEvent) -> Unit)
    abstract fun <E> Service<E>.callOnFailed(action: (WorkerStateEvent) -> Unit)

    @Test
    fun onReady() {
        service.callOnReady {
            assertEquals(service, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_READY, it.eventType)
        }
        service.onReady.handle(WorkerStateEvent(service, WorkerStateEvent.WORKER_STATE_READY))
    }

    @Test
    fun onScheduled() {
        service.callOnScheduled {
            assertEquals(service, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_SCHEDULED, it.eventType)
        }
        service.onScheduled.handle(WorkerStateEvent(service, WorkerStateEvent.WORKER_STATE_SCHEDULED))
    }

    @Test
    fun onRunning() {
        service.callOnRunning {
            assertEquals(service, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_RUNNING, it.eventType)
        }
        service.onRunning.handle(WorkerStateEvent(service, WorkerStateEvent.WORKER_STATE_RUNNING))
    }

    @Test
    fun onSucceeded() {
        service.callOnSucceeded {
            assertEquals(service, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_SUCCEEDED, it.eventType)
        }
        service.onSucceeded.handle(WorkerStateEvent(service, WorkerStateEvent.WORKER_STATE_SUCCEEDED))
    }

    @Test
    fun onCancelled() {
        service.callOnCancelled {
            assertEquals(service, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_CANCELLED, it.eventType)
        }
        service.onCancelled.handle(WorkerStateEvent(service, WorkerStateEvent.WORKER_STATE_CANCELLED))
    }

    @Test
    fun onFailed() {
        service.callOnFailed {
            assertEquals(service, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_FAILED, it.eventType)
        }
        service.onFailed.handle(WorkerStateEvent(service, WorkerStateEvent.WORKER_STATE_FAILED))
    }
}

<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/controls/TextFieldsTest.kt<|end_filename|>
package ktfx.controlsfx.controls

import com.hendraanggrian.ktfx.test.initToolkit
import javafx.scene.control.TextField
import ktfx.text.buildStringConverter
import kotlin.test.BeforeTest
import kotlin.test.Test

class TextFieldsTest {
    private lateinit var field: TextField

    @BeforeTest
    fun start() {
        initToolkit()
        field = TextField()
    }

    @Test
    fun bindAutoCompletion() {
        field.bindAutoCompletion("Hello", "World")
        field.bindAutoCompletion(listOf("Hello", "World"))
        field.bindAutoCompletion { listOf("Hello", "World") }
        field.bindAutoCompletion(buildStringConverter {}) { listOf("Hello", "World") }
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXDrawerTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXDrawer
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXDrawerTest : LayoutsTest<KtfxPane, JFXDrawer>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxDrawer { }
    override fun KtfxPane.child2() = jfxDrawer()
    override fun KtfxPane.child3() = jfxDrawer { }
}

<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_ListView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.control.ListView
import javafx.scene.control.ScrollToEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Int
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see ListView.setOnEditStart
 */
public fun <T> ListView<T>.onEditStart(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ListView.EditEvent<T>) -> Unit
) {
    return setOnEditStart { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ListView.setOnEditCommit
 */
public fun <T> ListView<T>.onEditCommit(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ListView.EditEvent<T>) -> Unit
) {
    return setOnEditCommit { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ListView.setOnEditCancel
 */
public fun <T> ListView<T>.onEditCancel(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ListView.EditEvent<T>) -> Unit
) {
    return setOnEditCancel { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ListView.setOnScrollTo
 */
public fun <T> ListView<T>.onScrollTo(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ScrollToEvent<Int>) -> Unit
) {
    return setOnScrollTo { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-commons/src/ktfx/collections/ObservableCollectionsMap.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ObservableCollectionsKt")
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.collections

import javafx.collections.FXCollections
import javafx.collections.ObservableMap
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
 * Returns an empty read-only [ObservableMap].
 * @see emptyMap
 */
inline fun <K, V> emptyObservableMap(): ObservableMap<K, V> = FXCollections.emptyObservableMap()

/**
 * Returns a new read-only [ObservableMap] of given pairs.
 * @see mapOf
 */
fun <K, V> observableMapOf(vararg pairs: Pair<K, V>): ObservableMap<K, V> =
    if (pairs.isNotEmpty()) FXCollections.unmodifiableObservableMap(pairs.toMap(FXCollections.observableHashMap()))
    else emptyObservableMap()

/**
 * Returns an empty read-only [ObservableMap].
 * @see mapOf
 */
inline fun <K, V> observableMapOf(): ObservableMap<K, V> = emptyObservableMap()

/**
 * Returns an empty [ObservableMap].
 * @see mutableMapOf
 */
inline fun <K, V> mutableObservableMapOf(): ObservableMap<K, V> = FXCollections.observableHashMap()

/**
 * Returns a new [ObservableMap] with the given elements.
 * @see mutableMapOf
 */
fun <K, V> mutableObservableMapOf(vararg pairs: Pair<K, V>): ObservableMap<K, V> =
    if (pairs.isEmpty()) mutableObservableMapOf()
    else FXCollections.observableMap(HashMap<K, V>().apply { for ((key, value) in pairs) put(key, value) })

/**
 * Builds a new read-only [ObservableMap] by populating a [MutableMap]
 * using the given [builderAction] and returning a read-only map with the same elements.
 * @see buildMap
 */
@ExperimentalStdlibApi
inline fun <K, V> buildObservableMap(builderAction: MutableMap<K, V>.() -> Unit): Map<K, V> {
    contract { callsInPlace(builderAction, InvocationKind.EXACTLY_ONCE) }
    return buildMap(builderAction).toObservableMap()
}

/**
 * Returns an [ObservableMap] containing all elements.
 * @see Map.toMap
 */
fun <K, V> Map<K, V>.toObservableMap(): ObservableMap<K, V> = when (size) {
    0 -> emptyObservableMap()
    else -> FXCollections.unmodifiableObservableMap(this.toMutableObservableMap())
}

/**
 * Returns a new [ObservableMap] filled with all elements of this map.
 * @see Map.toMutableMap
 */
inline fun <K, V> Map<K, V>.toMutableObservableMap(): ObservableMap<K, V> = FXCollections.observableMap(this)


<|start_filename|>ktfx-commons/src/ktfx/windows/FileChoosers.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.windows

import javafx.stage.DirectoryChooser
import javafx.stage.FileChooser
import javafx.stage.FileChooser.ExtensionFilter
import javafx.stage.Window
import java.io.File

/**
 * Choose a directory.
 * @param title title of the dialog.
 * @param initialDirectory starting point of chooser.
 * @return chosen directory.
 */
fun Window.chooseDirectory(
    title: String? = null,
    initialDirectory: File? = null
): File? = DirectoryChooser().also {
    if (title != null) it.title = title
    if (initialDirectory != null) it.initialDirectory = initialDirectory
}.showDialog(this)

/**
 * Choose a file to open.
 * @param title title of the dialog.
 * @param initialDirectory starting point of chooser.
 * @param initialFileName starting name of file to be choosen.
 * @param filters expected file extensions.
 * @return chosen file.
 */
fun Window.chooseFile(
    title: String? = null,
    initialDirectory: File? = null,
    initialFileName: String? = null,
    vararg filters: ExtensionFilter
): File? = FileChooser().also {
    if (title != null) it.title = title
    if (initialDirectory != null) it.initialDirectory = initialDirectory
    if (initialFileName != null) it.initialFileName = initialFileName
    if (filters.isNotEmpty()) it.extensionFilters += filters
}.showOpenDialog(this)

/**
 * Choose a file to open.
 * @param title title of the dialog.
 * @param initialDirectory starting point of chooser.
 * @param initialFileName starting name of file to be choosen.
 * @param filters expected file extensions.
 * @return chosen file.
 */
inline fun Window.chooseFile(
    title: String? = null,
    initialDirectory: File? = null,
    initialFileName: String? = null,
    vararg filters: Pair<String, String>
): File? = chooseFile(title, initialDirectory, initialFileName, *filters.asExtensionFilters())

/**
 * Choose a file to open.
 * @param filters expected file extensions.
 * @return chosen file.
 */
inline fun Window.chooseFile(vararg filters: ExtensionFilter): File? = chooseFile(null, null, null, *filters)

/**
 * Choose a file to open.
 * @param filters expected file extensions.
 * @return chosen file.
 */
inline fun Window.chooseFile(vararg filters: Pair<String, String>): File? = chooseFile(null, null, null, *filters)

/**
 * Choose multiple files to open.
 * @param title title of the dialog.
 * @param initialDirectory starting point of chooser.
 * @param initialFileName starting name of file to be choosen.
 * @param filters expected file extensions.
 * @return chosen files.
 */
fun Window.chooseFiles(
    title: String? = null,
    initialDirectory: File? = null,
    initialFileName: String? = null,
    vararg filters: ExtensionFilter
): List<File> = FileChooser().also {
    if (title != null) it.title = title
    if (initialDirectory != null) it.initialDirectory = initialDirectory
    if (initialFileName != null) it.initialFileName = initialFileName
    if (filters.isNotEmpty()) it.extensionFilters += filters
}.showOpenMultipleDialog(this)

/**
 * Choose multiple files to open.
 * @param title title of the dialog.
 * @param initialDirectory starting point of chooser.
 * @param initialFileName starting name of file to be choosen.
 * @param filters expected file extensions.
 * @return chosen files.
 */
inline fun Window.chooseFiles(
    title: String? = null,
    initialDirectory: File? = null,
    initialFileName: String? = null,
    vararg filters: Pair<String, String>
): List<File> = chooseFiles(title, initialDirectory, initialFileName, *filters.asExtensionFilters())

/**
 * Choose multiple files to open.
 * @param filters expected file extensions.
 * @return chosen files.
 */
inline fun Window.chooseFiles(vararg filters: ExtensionFilter): List<File> = chooseFiles(null, null, null, *filters)

/**
 * Choose multiple files to open.
 * @param filters expected file extensions.
 * @return chosen files.
 */
inline fun Window.chooseFiles(vararg filters: Pair<String, String>): List<File> =
    chooseFiles(null, null, null, *filters)

/**
 * Choose a file to save.
 * @param title title of the dialog.
 * @param initialDirectory starting point of chooser.
 * @param initialFileName starting name of file to be choosen.
 * @param filters expected file extensions.
 * @return chosen file.
 */
fun Window.chooseSaveFile(
    title: String? = null,
    initialDirectory: File? = null,
    initialFileName: String? = null,
    vararg filters: ExtensionFilter
): File? = FileChooser().also {
    if (title != null) it.title = title
    if (initialDirectory != null) it.initialDirectory = initialDirectory
    if (initialFileName != null) it.initialFileName = initialFileName
    if (filters.isNotEmpty()) it.extensionFilters += filters
}.showSaveDialog(this)

/**
 * Choose a file to save.
 * @param title title of the dialog.
 * @param initialDirectory starting point of chooser.
 * @param initialFileName starting name of file to be choosen.
 * @param filters expected file extensions.
 * @return chosen file.
 */
inline fun Window.chooseSaveFile(
    title: String? = null,
    initialDirectory: File? = null,
    initialFileName: String? = null,
    vararg filters: Pair<String, String>
): File? = chooseSaveFile(title, initialDirectory, initialFileName, *filters.asExtensionFilters())

/**
 * Choose a file to save.
 * @param filters expected file extensions.
 * @return chosen file.
 */
inline fun Window.chooseSaveFile(vararg filters: ExtensionFilter): File? = chooseSaveFile(null, null, null, *filters)

/**
 * Choose a file to save.
 * @param filters expected file extensions.
 * @return chosen file.
 */
inline fun Window.chooseSaveFile(vararg filters: Pair<String, String>): File? =
    chooseSaveFile(null, null, null, *filters)

@PublishedApi
internal inline fun Array<out Pair<String, String>>.asExtensionFilters(): Array<ExtensionFilter> =
    map { ExtensionFilter(it.first, it.second) }.toTypedArray()


<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/DialogTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.control.Dialog
import javafx.scene.control.DialogEvent
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseDialogTest
import kotlin.test.Ignore

@Ignore
class DialogTest : BaseDialogTest() {

    override fun <E> Dialog<E>.callOnCloseRequest(action: (DialogEvent) -> Unit) =
        onCloseRequest(Dispatchers.Unconfined) { action(it) }

    override fun <E> Dialog<E>.callOnShowing(action: (DialogEvent) -> Unit) =
        onShowing(Dispatchers.Unconfined) { action(it) }

    override fun <E> Dialog<E>.callOnShown(action: (DialogEvent) -> Unit) =
        onShown(Dispatchers.Unconfined) { action(it) }

    override fun <E> Dialog<E>.callOnHiding(action: (DialogEvent) -> Unit) =
        onHiding(Dispatchers.Unconfined) { action(it) }

    override fun <E> Dialog<E>.callOnHidden(action: (DialogEvent) -> Unit) =
        onHidden(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/collections/BaseObservableMapTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.collections.FXCollections
import javafx.collections.MapChangeListener
import javafx.collections.ObservableMap
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

abstract class BaseObservableMapTest {

    abstract fun <K, V> ObservableMap<K, V>.callListener(action: (MapChangeListener.Change<out K, out V>) -> Unit)

    @Test
    fun listener() {
        val map = FXCollections.observableHashMap<Int, String>()
        map.callListener<Int, String> {
            assertTrue(it.wasAdded())
            assertEquals(1, it.key)
            assertEquals("Hello world", it.valueAdded)
        }
        map[1] = "Hello world"
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseButtonBaseTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.ActionEvent
import javafx.scene.control.Button
import javafx.scene.control.ButtonBase
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseButtonBaseTest {

    abstract fun ButtonBase.callOnAction(action: (ActionEvent) -> Unit)

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun onAction() {
        val button = Button()
        button.callOnAction {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
        }
        button.onAction.handle(ActionEvent(this, FakeEventTarget))
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXSpinnerTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXSpinner
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class JFXSpinnerTest : LayoutsTest<KtfxPane, JFXSpinner>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxSpinner { }
    override fun KtfxPane.child2() = jfxSpinner()
    override fun KtfxPane.child3() = jfxSpinner { }

    override fun JFXSpinner.testDefaultValues() {
        assertEquals(JFXSpinner.INDETERMINATE_PROGRESS, progress)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/windows/Window.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.windows

import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.GestureEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.TouchPoint
import javafx.stage.Window

/** Move [Window] to specified location. */
fun Window.moveTo(x: Number, y: Number) {
    this.x = x.toDouble()
    this.y = y.toDouble()
}

/** Move [Window] to specified location using [ContextMenuEvent]. */
inline fun Window.moveTo(event: ContextMenuEvent): Unit = moveTo(event.screenX, event.screenY)

/** Move [Window] to specified location using [DragEvent]. */
inline fun Window.moveTo(event: DragEvent): Unit = moveTo(event.screenX, event.screenY)

/** Move [Window] to specified location using [GestureEvent]. */
inline fun Window.moveTo(event: GestureEvent): Unit = moveTo(event.screenX, event.screenY)

/** Move [Window] to specified location using [MouseEvent]. */
inline fun Window.moveTo(event: MouseEvent): Unit = moveTo(event.screenX, event.screenY)

/** Move [Window] to specified location using [TouchPoint]. */
inline fun Window.moveTo(event: TouchPoint): Unit = moveTo(event.screenX, event.screenY)


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXPasswordFieldTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXPasswordField
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXPasswordFieldTest : LayoutsTest<KtfxPane, JFXPasswordField>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxPasswordField { }
    override fun KtfxPane.child2() = jfxPasswordField()
    override fun KtfxPane.child3() = jfxPasswordField { }
}

<|start_filename|>ktfx-commons/src/ktfx/Pair.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx

/**
 * Returns the key component of the pair.
 *
 * This method allows to use destructuring declarations when working with pairs (e.g.: `val (first, second) = myPair`).
 */
inline operator fun <F, S> javafx.util.Pair<F, S>.component1(): F? = key

/**
 * Returns the value component of the pair.
 *
 * This method allows to use destructuring declarations when working with pairs (e.g.: `val (first, second) = myPair`).
 */
inline operator fun <F, S> javafx.util.Pair<F, S>.component2(): S? = value

/** Returns this [Pair] as a [kotlin.Pair]. */
inline fun <F, S> javafx.util.Pair<F, S>.toKotlinPair(): Pair<F, S> = Pair(key, value)

/** Returns this [kotlin.Pair] as a JavaFX [Pair]. */
inline fun <F, S> Pair<F, S>.toFxPair(): javafx.util.Pair<F, S> = javafx.util.Pair(first, second)


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/layouts/ControlsFx.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.layouts

import com.hendraanggrian.kotlinpoet.asNullable
import com.hendraanggrian.kotlinpoet.memberOf
import com.hendraanggrian.kotlinpoet.parameterizedBy
import com.hendraanggrian.kotlinpoet.typeVarBy
import com.hendraanggrian.kotlinpoet.typeVarOf
import com.hendraanggrian.ktfx.codegen.T
import javafx.collections.ObservableList
import javafx.concurrent.Task
import javafx.geometry.Side
import javafx.scene.control.CheckBoxTreeItem
import org.controlsfx.control.BreadCrumbBar
import org.controlsfx.control.CheckComboBox
import org.controlsfx.control.CheckListView
import org.controlsfx.control.CheckTreeView
import org.controlsfx.control.GridView
import org.controlsfx.control.HiddenSidesPane
import org.controlsfx.control.HyperlinkLabel
import org.controlsfx.control.InfoOverlay
import org.controlsfx.control.ListSelectionView
import org.controlsfx.control.MaskerPane
import org.controlsfx.control.MasterDetailPane
import org.controlsfx.control.NotificationPane
import org.controlsfx.control.PlusMinusSlider
import org.controlsfx.control.PrefixSelectionChoiceBox
import org.controlsfx.control.PrefixSelectionComboBox
import org.controlsfx.control.PropertySheet
import org.controlsfx.control.RangeSlider
import org.controlsfx.control.Rating
import org.controlsfx.control.SegmentedBar
import org.controlsfx.control.SegmentedButton
import org.controlsfx.control.SnapshotView
import org.controlsfx.control.StatusBar
import org.controlsfx.control.TaskProgressView
import org.controlsfx.control.ToggleSwitch
import org.controlsfx.control.WorldMapView
import org.controlsfx.control.textfield.CustomPasswordField
import org.controlsfx.control.textfield.CustomTextField

val LayoutsFactory.Companion.ControlsFx: LayoutsFactory
    get() = object : LayoutsFactory(
        "thirdparty/controlsfx-layouts/src", "ktfx.controlsfx.layouts", "ControlsFxLayoutsKt"
    ) {
        init {
            // org.controlsfx.control.textfield
            CustomPasswordField::class()
            CustomTextField::class()

            // org.controlsfx.control
            BreadCrumbBar::class(T) { treeItem("selectedCrumb", T) }
            CheckComboBox::class(T) { items(T) }
            CheckListView::class(T) { items(T) }
            CheckTreeView::class(T) {
                "root"(CheckBoxTreeItem::class.parameterizedBy(T).asNullable()) { defaultValue("null") }
            }
            GridView::class(T) { items(T) }
            HiddenSidesPane::class(customClass = true)
            HyperlinkLabel::class{ text() }
            InfoOverlay::class(customClass = true) { content(); text(); }
            ListSelectionView::class(T)
            MaskerPane::class()
            MasterDetailPane::class(customClass = true) {
                "detailSide"<Side> { defaultValue("%M", Side::class.memberOf("RIGHT")) }
                "showDetailNode"<Boolean> { defaultValue("true") }
            }
            NotificationPane::class(customClass = true)
            PlusMinusSlider::class()
            PrefixSelectionChoiceBox::class(T)
            PrefixSelectionComboBox::class(T)
            PropertySheet::class {
                "items"(ObservableList::class.parameterizedBy(PropertySheet.Item::class).asNullable()) {
                    defaultValue("null")
                }
            }
            RangeSlider::class {
                "min"<Double> { defaultValue("0.0") }
                "max"<Double> { defaultValue("1.0") }
                "lowValue"<Double> { defaultValue("0.25") }
                "highValue"<Double> { defaultValue("0.75") }
            }
            Rating::class {
                "max"<Int> { defaultValue("5") }
                "rating"<Int> { defaultValue("-1") }
            }
            SegmentedBar::class("T".typeVarBy(SegmentedBar.Segment::class))
            SegmentedButton::class(customClass = true)
            SnapshotView::class(customClass = true)
            StatusBar::class()
            TaskProgressView::class("T".typeVarBy(Task::class.parameterizedBy("*".typeVarOf())))
            ToggleSwitch::class { text() }
            WorldMapView::class()
        }
    }

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_FlowPane1.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.geometry.Orientation
import javafx.geometry.Orientation.HORIZONTAL
import javafx.scene.layout.FlowPane
import kotlin.Double
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [FlowPane] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.flowPane(orientation: Orientation = HORIZONTAL, gap: Double = 0.0): FlowPane =
    flowPane(orientation = orientation, gap = gap) { }

/**
 * Create a [FlowPane] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun flowPane(
    orientation: Orientation = HORIZONTAL,
    gap: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker KtfxFlowPane).() -> Unit
): FlowPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxFlowPane(orientation, gap)
    child.configuration()
    return child
}

/**
 * Add a [FlowPane] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.flowPane(
    orientation: Orientation = HORIZONTAL,
    gap: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker KtfxFlowPane).() -> Unit
): FlowPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxFlowPane(orientation, gap)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [FlowPane].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledFlowPane(
    orientation: Orientation = HORIZONTAL,
    gap: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): FlowPane = styledFlowPane(
    orientation = orientation, gap = gap, styleClass = *styleClass,
    id =
    id
) { }

/**
 * Add a styled [FlowPane] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledFlowPane(
    orientation: Orientation = HORIZONTAL,
    gap: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): FlowPane = styledFlowPane(
    orientation = orientation, gap = gap, styleClass = *styleClass,
    id =
    id
) { }

/**
 * Create a styled [FlowPane] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledFlowPane(
    orientation: Orientation = HORIZONTAL,
    gap: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxFlowPane).() -> Unit
): FlowPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxFlowPane(orientation, gap)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [FlowPane] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledFlowPane(
    orientation: Orientation = HORIZONTAL,
    gap: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxFlowPane).() -> Unit
): FlowPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxFlowPane(orientation, gap)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-commons/tests/src/ktfx/jfoenix/controls/JFXNodeUtilsTest.kt<|end_filename|>
package ktfx.jfoenix.controls

import com.hendraanggrian.ktfx.test.initToolkit
import com.jfoenix.utils.JFXNodeUtils
import javafx.geometry.Insets
import javafx.scene.control.Label
import javafx.scene.layout.Background
import javafx.scene.layout.BackgroundFill
import javafx.scene.layout.CornerRadii
import javafx.scene.paint.Color
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

class JFXNodeUtilsTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun updateBackground() {
        val node = Label("Hello world")
        val placeholderBackground = Background(BackgroundFill(Color.BLUE, CornerRadii.EMPTY, Insets.EMPTY))

        node.updateBackground(placeholderBackground)
        assertEquals(Color.BLACK, node.background.fills.first().fill)

        node.updateBackground(placeholderBackground, Color.RED)
        assertEquals(Color.RED, node.background.fills.first().fill)
    }

    @Test
    fun toHex() = assertEquals(Color.BLUE.toHex(), JFXNodeUtils.colorToHex(Color.BLUE))
}

<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_Tab.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.event.Event
import javafx.scene.control.Tab
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Tab.setOnSelectionChanged
 */
public fun Tab.onSelectionChanged(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnSelectionChanged { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Tab.setOnClosed
 */
public fun Tab.onClosed(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnClosed { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Tab.setOnCloseRequest
 */
public fun Tab.onCloseRequest(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnCloseRequest { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXListViewTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXListView
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXListViewTest : LayoutsTest<KtfxPane, JFXListView<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxListView<String> { }
    override fun KtfxPane.child2() = jfxListView<String>()
    override fun KtfxPane.child3() = jfxListView<String> { }
}

<|start_filename|>ktfx-commons/src/ktfx/Callback.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx

import javafx.util.Callback

/** Create new callback using Kotlin function type. */
inline fun <P, R> callbackOf(noinline callback: (P) -> R?): Callback<P, R> = Callback { callback(it) }

/** Converts the object provided into its string form. */
@Suppress("NOTHING_TO_INLINE")
inline operator fun <P, R> Callback<P, R>.invoke(obj: P): R = call(obj)


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXColorPickerTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXColorPicker
import javafx.scene.paint.Color
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class JFXColorPickerTest : LayoutsTest<KtfxPane, JFXColorPicker>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxColorPicker { }
    override fun KtfxPane.child2() = jfxColorPicker()
    override fun KtfxPane.child3() = jfxColorPicker { }

    override fun JFXColorPicker.testDefaultValues() {
        assertEquals(Color.WHITE, value)
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseTableViewTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.TableColumn
import javafx.scene.control.TablePosition
import javafx.scene.control.TableView
import javafx.util.Duration
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseTableViewTest {
    private lateinit var table: TableView<Duration>
    private lateinit var column: TableColumn<Duration, Long>
    private lateinit var position: TablePosition<Duration, Long>

    abstract fun <S> TableView<S>.callOnSort(action: (SortEvent<TableView<S>>) -> Unit)
    abstract fun <S> TableView<S>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit)
    abstract fun <S> TableView<S>.callOnScrollToColumn(action: (ScrollToEvent<TableColumn<S, *>>) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        table = TableView()
        table.columns += TableColumn<Duration, Long>().also { column = it }
        position = TablePosition(table, 0, column)
    }

    @Test
    fun onSort() {
        table.callOnSort {
            assertEquals(table, it.source)
            assertEquals(FakeEventTarget, it.target)
        }
        table.onSort.handle(SortEvent(table, FakeEventTarget))
    }

    @Test
    fun onScrollTo() {
        table.callOnScrollTo {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(ScrollToEvent.scrollToTopIndex(), it.eventType)
            assertEquals(0, it.scrollTarget)
        }
        table.onScrollTo.handle(ScrollToEvent(this, FakeEventTarget, ScrollToEvent.scrollToTopIndex(), 0))
    }

    @Test
    fun onScrollToColumn() {
        table.callOnScrollToColumn {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(ScrollToEvent.scrollToColumn<TableColumn<Duration, Long>>(), it.eventType)
            assertEquals(column, it.scrollTarget)
        }
        table.onScrollToColumn.handle(ScrollToEvent(this, FakeEventTarget, ScrollToEvent.scrollToColumn(), column))
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseMenuTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.Event
import javafx.scene.control.Menu
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseMenuTest {
    private lateinit var menu: Menu

    abstract fun Menu.callOnShowing(action: (Event) -> Unit)
    abstract fun Menu.callOnShown(action: (Event) -> Unit)
    abstract fun Menu.callOnHiding(action: (Event) -> Unit)
    abstract fun Menu.callOnHidden(action: (Event) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        menu = Menu()
    }

    @Test
    fun onShowing() {
        menu.callOnShowing {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        menu.onShowing.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onShown() {
        menu.callOnShown {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        menu.onShown.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onHiding() {
        menu.callOnHiding {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        menu.onHiding.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onHidden() {
        menu.callOnHidden {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        menu.onHidden.handle(Event(this, FakeEventTarget, Event.ANY))
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/BreadCrumbBarTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.BreadCrumbBar
import kotlin.test.assertNull

class BreadCrumbBarTest : LayoutsTest<KtfxPane, BreadCrumbBar<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = breadCrumbBar<String> { }
    override fun KtfxPane.child2() = breadCrumbBar<String>()
    override fun KtfxPane.child3() = breadCrumbBar<String> { }

    override fun BreadCrumbBar<String>.testDefaultValues() {
        assertNull(selectedCrumb)
    }
}

<|start_filename|>ktfx-layouts/src/javafx/scene/control/KtfxAccordion.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.Accordion
import javafx.scene.control.TitledPane
import kotlin.contracts.ExperimentalContracts

/**
 * [Accordion] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxAccordion : Accordion(), TitledPaneManager {

    final override fun <C : TitledPane> addChild(child: C): C = child.also { panes += it }

    /** Call [NodeManager.titledPane] by string invocation. */
    inline operator fun String.invoke(
        configuration: (@KtfxLayoutDslMarker KtfxTitledPane).() -> Unit
    ): TitledPane = titledPane(this, configuration)
}


<|start_filename|>thirdparty/jfoenix-layouts/src/com/jfoenix/controls/KtfxJFXBadge.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXBadge
import javafx.scene.Node
import ktfx.layouts.NodeManager
import kotlin.contracts.ExperimentalContracts

/**
 * [JFXBadge] with dynamic-layout dsl support.
 * Invoking dsl will only set its control.
 */
open class KtfxJFXBadge : JFXBadge(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { control = it }
}


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_Animation.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.animation.Animation
import javafx.event.ActionEvent
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Animation.setOnFinished
 */
public inline fun Animation.onFinished(noinline action: (ActionEvent) -> Unit) {
    return setOnFinished(action)
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_ArcTo.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.ArcTo
import kotlin.Boolean
import kotlin.Double
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add an [ArcTo] to this manager.
 *
 * @return the control added.
 */
public fun PathElementManager.arcTo(
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    xAxisRotation: Double = 0.0,
    x: Double = 0.0,
    y: Double = 0.0,
    largeArcFlag: Boolean = false,
    sweepFlag: Boolean = false
): ArcTo = arcTo(
    radiusX = radiusX, radiusY = radiusY, xAxisRotation = xAxisRotation, x = x, y = y,
    largeArcFlag = largeArcFlag, sweepFlag = sweepFlag
) { }

/**
 * Create an [ArcTo] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun arcTo(
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    xAxisRotation: Double = 0.0,
    x: Double = 0.0,
    y: Double = 0.0,
    largeArcFlag: Boolean = false,
    sweepFlag: Boolean = false,
    configuration: (@KtfxLayoutDslMarker ArcTo).() -> Unit
): ArcTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ArcTo(radiusX, radiusY, xAxisRotation, x, y, largeArcFlag, sweepFlag)
    child.configuration()
    return child
}

/**
 * Add an [ArcTo] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun PathElementManager.arcTo(
    radiusX: Double = 0.0,
    radiusY: Double = 0.0,
    xAxisRotation: Double = 0.0,
    x: Double = 0.0,
    y: Double = 0.0,
    largeArcFlag: Boolean = false,
    sweepFlag: Boolean = false,
    configuration: (@KtfxLayoutDslMarker ArcTo).() -> Unit
): ArcTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ArcTo(radiusX, radiusY, xAxisRotation, x, y, largeArcFlag, sweepFlag)
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXCheckBox.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXCheckBox
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXCheckBox] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.jfxCheckBox(text: String? = null): JFXCheckBox = jfxCheckBox(text = text) { }

/**
 * Create a [JFXCheckBox] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun jfxCheckBox(
    text: String? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        JFXCheckBox
    ).() -> Unit
): JFXCheckBox {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXCheckBox(text)
    child.configuration()
    return child
}

/**
 * Add a [JFXCheckBox] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.jfxCheckBox(
    text: String? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        JFXCheckBox
    ).() -> Unit
): JFXCheckBox {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXCheckBox(text)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXCheckBox].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledJFXCheckBox(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null
): JFXCheckBox = styledJFXCheckBox(text = text, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXCheckBox] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledJFXCheckBox(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null
): JFXCheckBox = styledJFXCheckBox(text = text, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [JFXCheckBox] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledJFXCheckBox(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXCheckBox).() -> Unit
): JFXCheckBox {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXCheckBox(text)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXCheckBox] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledJFXCheckBox(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXCheckBox).() -> Unit
): JFXCheckBox {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXCheckBox(text)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-commons/tests/src/ktfx/jfoenix/controls/JFXDepthManagerTest.kt<|end_filename|>
package ktfx.jfoenix.controls

import com.hendraanggrian.ktfx.test.initToolkit
import com.jfoenix.effects.JFXDepthManager
import javafx.scene.Node
import javafx.scene.control.Label
import javafx.scene.effect.BlurType
import javafx.scene.effect.DropShadow
import javafx.scene.paint.Color
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

class JFXDepthManagerTest {
    private lateinit var node: Node

    @BeforeTest
    fun start() {
        initToolkit()
        node = Label("Hello world")
    }

    @Test
    fun depth() {
        node.depth = 1
        assertDepth(node, 1)
    }

    @Test
    fun wrapDepth() {
        node.wrapDepth(2)
        assertDepth(node.parent, 2)
    }

    @Test
    fun popDepth() {
        node.popDepth()
        val shadow = node.effect as DropShadow
        assertEquals(BlurType.GAUSSIAN, shadow.blurType)
        assertEquals(Color.rgb(0, 0, 0, 0.26), shadow.color)
        assertEquals(5.0, shadow.radius)
        assertEquals(0.05, shadow.spread)
        assertEquals(0.0, shadow.offsetX)
        assertEquals(1.0, shadow.offsetY)
    }

    private fun assertDepth(node: Node, level: Int) {
        val actualShadow = node.effect as DropShadow
        val managedShadow = JFXDepthManager.getShadowAt(level)
        assertEquals(BlurType.GAUSSIAN, actualShadow.blurType)
        assertEquals(managedShadow.color, actualShadow.color)
        assertEquals(managedShadow.radius, actualShadow.radius)
        assertEquals(managedShadow.spread, actualShadow.spread)
        assertEquals(managedShadow.offsetX, actualShadow.offsetX)
        assertEquals(managedShadow.offsetY, actualShadow.offsetY)
    }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/NodeTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.Node
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent
import com.hendraanggrian.ktfx.test.BaseNodeTest

class NodeTest : BaseNodeTest() {

    override fun Node.callOnDragEntered(action: (DragEvent) -> Unit) = onDragEntered(action)
    override fun Node.callOnDragExited(action: (DragEvent) -> Unit) = onDragExited(action)
    override fun Node.callOnDragOver(action: (DragEvent) -> Unit) = onDragOver(action)
    override fun Node.callOnDragDropped(action: (DragEvent) -> Unit) = onDragDropped(action)
    override fun Node.callOnDragDone(action: (DragEvent) -> Unit) = onDragDone(action)
    override fun Node.callOnContextMenuRequested(action: (ContextMenuEvent) -> Unit) = onContextMenuRequested(action)
    override fun Node.callOnMouseClicked(action: (MouseEvent) -> Unit) = onMouseClicked(action)
    override fun Node.callOnMouseDragged(action: (MouseEvent) -> Unit) = onMouseDragged(action)
    override fun Node.callOnMouseEntered(action: (MouseEvent) -> Unit) = onMouseEntered(action)
    override fun Node.callOnMouseExited(action: (MouseEvent) -> Unit) = onMouseExited(action)
    override fun Node.callOnMouseMoved(action: (MouseEvent) -> Unit) = onMouseMoved(action)
    override fun Node.callOnMousePressed(action: (MouseEvent) -> Unit) = onMousePressed(action)
    override fun Node.callOnMouseReleased(action: (MouseEvent) -> Unit) = onMouseReleased(action)
    override fun Node.callOnDragDetected(action: (MouseEvent) -> Unit) = onDragDetected(action)
    override fun Node.callOnMouseDragOver(action: (MouseDragEvent) -> Unit) = onMouseDragOver(action)
    override fun Node.callOnMouseDragReleased(action: (MouseDragEvent) -> Unit) = onMouseDragReleased(action)
    override fun Node.callOnMouseDragEntered(action: (MouseDragEvent) -> Unit) = onMouseDragEntered(action)
    override fun Node.callOnMouseDragExited(action: (MouseDragEvent) -> Unit) = onMouseDragExited(action)
    override fun Node.callOnScrollStarted(action: (ScrollEvent) -> Unit) = onScrollStarted(action)
    override fun Node.callOnScroll(action: (ScrollEvent) -> Unit) = onScroll(action)
    override fun Node.callOnScrollFinished(action: (ScrollEvent) -> Unit) = onScrollFinished(action)
    override fun Node.callOnRotationStarted(action: (RotateEvent) -> Unit) = onRotationStarted(action)
    override fun Node.callOnRotate(action: (RotateEvent) -> Unit) = onRotate(action)
    override fun Node.callOnRotationFinished(action: (RotateEvent) -> Unit) = onRotationFinished(action)
    override fun Node.callOnZoomStarted(action: (ZoomEvent) -> Unit) = onZoomStarted(action)
    override fun Node.callOnZoom(action: (ZoomEvent) -> Unit) = onZoom(action)
    override fun Node.callOnZoomFinished(action: (ZoomEvent) -> Unit) = onZoomFinished(action)
    override fun Node.callOnSwipeUp(action: (SwipeEvent) -> Unit) = onSwipeUp(action)
    override fun Node.callOnSwipeDown(action: (SwipeEvent) -> Unit) = onSwipeDown(action)
    override fun Node.callOnSwipeRight(action: (SwipeEvent) -> Unit) = onSwipeRight(action)
    override fun Node.callOnSwipeLeft(action: (SwipeEvent) -> Unit) = onSwipeLeft(action)
    override fun Node.callOnTouchPressed(action: (TouchEvent) -> Unit) = onTouchPressed(action)
    override fun Node.callOnTouchMoved(action: (TouchEvent) -> Unit) = onTouchMoved(action)
    override fun Node.callOnTouchReleased(action: (TouchEvent) -> Unit) = onTouchReleased(action)
    override fun Node.callOnTouchStationary(action: (TouchEvent) -> Unit) = onTouchStationary(action)
    override fun Node.callOnKeyPressed(action: (KeyEvent) -> Unit) = onKeyPressed(action)
    override fun Node.callOnKeyReleased(action: (KeyEvent) -> Unit) = onKeyReleased(action)
    override fun Node.callOnKeyTyped(action: (KeyEvent) -> Unit) = onKeyTyped(action)
    override fun Node.callOnInputMethodTextChanged(action: (InputMethodEvent) -> Unit) =
        onInputMethodTextChanged(action)
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXDecoratorTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

// TODO: Do something about this
class JFXDecoratorTest

<|start_filename|>ktfx-layouts/src/javafx/scene/layout/KtfxHBox.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.layouts

import javafx.geometry.Insets
import javafx.scene.Node
import javafx.scene.layout.HBox
import javafx.scene.layout.Priority
import kotlin.contracts.ExperimentalContracts

/**
 * [HBox] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxHBox(spacing: Double) : HBox(spacing), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { children += it }

    /** Children horizontal grow priority in this layout. */
    inline var Node.hgrow: Priority?
        @JvmName("getHgrow2") get() = getHgrow(this)
        @JvmName("setHgrow2") set(value) = setHgrow(this, value)

    /** Configure [hgrow] fluidly. */
    fun <C : Node> C.hgrow(always: Boolean = true): C {
        hgrow = if (always) Priority.ALWAYS else Priority.NEVER
        return this
    }

    /** Children margin in this layout. */
    inline var Node.margin: Insets?
        @JvmName("getMargin2") get() = getMargin(this)
        @JvmName("setMargin2") set(value) = setMargin(this, value)

    /** Configure [margin] fluidly. */
    fun <C : Node> C.margin(insets: Insets): C {
        margin = insets
        return this
    }

    /** Clear children constraints. */
    @JvmName("clearConstraints2")
    inline fun Node.clearConstraints(): Unit = clearConstraints(this)
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXToggleButtonTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXToggleButton
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXToggleButtonTest : LayoutsTest<KtfxPane, JFXToggleButton>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxToggleButton { }
    override fun KtfxPane.child2() = jfxToggleButton()
    override fun KtfxPane.child3() = jfxToggleButton { }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_PrefixSelectionChoiceBox.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.PrefixSelectionChoiceBox
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [PrefixSelectionChoiceBox] to this manager.
 *
 * @return the control added.
 */
public fun <T> NodeManager.prefixSelectionChoiceBox(): PrefixSelectionChoiceBox<T> =
    prefixSelectionChoiceBox() { }

/**
 * Create a [PrefixSelectionChoiceBox] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun <T> prefixSelectionChoiceBox(
    configuration: (
        @KtfxLayoutDslMarker
        PrefixSelectionChoiceBox<T>
    ).() -> Unit
): PrefixSelectionChoiceBox<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PrefixSelectionChoiceBox<T>()
    child.configuration()
    return child
}

/**
 * Add a [PrefixSelectionChoiceBox] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun <T> NodeManager.prefixSelectionChoiceBox(
    configuration: (
        @KtfxLayoutDslMarker
        PrefixSelectionChoiceBox<T>
    ).() -> Unit
): PrefixSelectionChoiceBox<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PrefixSelectionChoiceBox<T>()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [PrefixSelectionChoiceBox].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun <T> styledPrefixSelectionChoiceBox(vararg styleClass: String, id: String? = null):
    PrefixSelectionChoiceBox<T> = styledPrefixSelectionChoiceBox(
    styleClass = *styleClass,
    id =
    id
) { }

/**
 * Add a styled [PrefixSelectionChoiceBox] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun <T> NodeManager.styledPrefixSelectionChoiceBox(
    vararg styleClass: String,
    id: String? =    
        null
): PrefixSelectionChoiceBox<T> = styledPrefixSelectionChoiceBox(
    styleClass =
    *styleClass,
    id = id
) { }

/**
 * Create a styled [PrefixSelectionChoiceBox] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun <T> styledPrefixSelectionChoiceBox(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker PrefixSelectionChoiceBox<T>).() -> Unit
): PrefixSelectionChoiceBox<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PrefixSelectionChoiceBox<T>()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [PrefixSelectionChoiceBox] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun <T> NodeManager.styledPrefixSelectionChoiceBox(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker PrefixSelectionChoiceBox<T>).() -> Unit
): PrefixSelectionChoiceBox<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PrefixSelectionChoiceBox<T>()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXToggleNodeTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXToggleNode
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class JFXToggleNodeTest : LayoutsTest<KtfxPane, JFXToggleNode>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxToggleNode { }
    override fun KtfxPane.child2() = jfxToggleNode()
    override fun KtfxPane.child3() = jfxToggleNode { }

    override fun JFXToggleNode.testDefaultValues() {
        assertNull(graphic)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/cells/ListCells.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.cells

import javafx.beans.value.ObservableValue
import javafx.collections.ObservableList
import javafx.scene.control.ComboBox
import javafx.scene.control.ListCell
import javafx.scene.control.ListView
import javafx.scene.control.cell.CheckBoxListCell
import javafx.scene.control.cell.ChoiceBoxListCell
import javafx.scene.control.cell.ComboBoxListCell
import javafx.scene.control.cell.TextFieldListCell
import javafx.util.StringConverter

/**
 * Sets a [CheckBoxListCell] factory for use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param selectedPropertyProvider A provider that, given an object from `ListView<T>.items`,
 *  will return an `ObservableValue<Boolean>` that represents whether the given item is selected or not.
 */
inline fun <T> ListView<T>.checkBoxCellFactory(
    noinline selectedPropertyProvider: (T) -> ObservableValue<Boolean>
): Unit = setCellFactory(CheckBoxListCell.forListView(selectedPropertyProvider))

/**
 * Sets a [CheckBoxListCell] factory for use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param selectedPropertyProvider A provider that, given an object from `ListView<T>.items`,
 *  will return an `ObservableValue<Boolean>` that represents whether the given item is selected or not.
 */
inline fun <T> ListView<T>.checkBoxCellFactory(
    converter: StringConverter<T>,
    noinline selectedPropertyProvider: (T) -> ObservableValue<Boolean>
): Unit = setCellFactory(CheckBoxListCell.forListView(selectedPropertyProvider, converter))

/**
 * Sets a [ChoiceBoxListCell] factory for use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <T> ListView<T>.choiceBoxCellFactory(
    vararg items: T
): Unit = setCellFactory(ChoiceBoxListCell.forListView(*items))

/**
 * Sets a [ChoiceBoxListCell] factory for use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <T> ListView<T>.choiceBoxCellFactory(
    converter: StringConverter<T>,
    vararg items: T
): Unit = setCellFactory(ChoiceBoxListCell.forListView(converter, *items))

/**
 * Sets a [ChoiceBoxListCell] factory for use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <T> ListView<T>.choiceBoxCellFactory(
    items: ObservableList<T>
): Unit = setCellFactory(ChoiceBoxListCell.forListView(items))

/**
 * Sets a [ChoiceBoxListCell] factory for use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <T> ListView<T>.choiceBoxCellFactory(
    converter: StringConverter<T>,
    items: ObservableList<T>
): Unit = setCellFactory(ChoiceBoxListCell.forListView(converter, items))

/**
 * Sets a [ComboBoxListCell] factory for use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <T> ListView<T>.comboBoxCellFactory(
    vararg items: T
): Unit = setCellFactory(ComboBoxListCell.forListView(*items))

/**
 * Sets a [ComboBoxListCell] factory for use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <T> ListView<T>.comboBoxCellFactory(
    converter: StringConverter<T>,
    vararg items: T
): Unit = setCellFactory(ComboBoxListCell.forListView(converter, *items))

/**
 * Sets a [ComboBoxListCell] factory for use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <T> ListView<T>.comboBoxCellFactory(
    items: ObservableList<T>
): Unit = setCellFactory(ComboBoxListCell.forListView(items))

/**
 * Sets a [ComboBoxListCell] factory for use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <T> ListView<T>.comboBoxCellFactory(
    converter: StringConverter<T>,
    items: ObservableList<T>
): Unit = setCellFactory(ComboBoxListCell.forListView(converter, items))

/**
 * Sets a [TextFieldListCell] factory for use in this [ListView].
 */
inline fun ListView<String>.textFieldCellFactory(): Unit =
    setCellFactory(TextFieldListCell.forListView())

/**
 * Sets a [TextFieldListCell] factory for use in this [ListView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 */
inline fun <T> ListView<T>.textFieldCellFactory(
    converter: StringConverter<T>
): Unit = setCellFactory(TextFieldListCell.forListView(converter))

/**
 * Sets a custom cell factory to use in this [ListView].
 * @param T The type of the elements contained within the [ListView].
 * @param configuration custom initialization block that configures [KtfxListCell].
 */
fun <T> ListView<T>.cellFactory(
    configuration: KtfxListCell<T>.(ListView<T>) -> Unit
): Unit = setCellFactory { KtfxListCell<T>().apply { configuration(it) } }

/**
 * Sets a custom cell factory to use in this [ComboBox].
 * @param T The type of the elements contained within the [ComboBox].
 * @param configuration custom initialization block that configures [KtfxListCell].
 */
fun <T> ComboBox<T>.cellFactory(
    configuration: KtfxListCell<T>.(ListView<T>) -> Unit
): Unit = setCellFactory { KtfxListCell<T>().apply { configuration(it) } }

/** Custom [ListCell] configurator class. */
class KtfxListCell<T> : ListCell<T>(), KtfxCell<T> {
    private var onEditStart: (() -> Unit)? = null
    private var onEditCommit: ((T?) -> Unit)? = null
    private var onEditCancel: (() -> Unit)? = null
    private var onUpdate: ((T?, empty: Boolean) -> Unit)? = null

    override fun onEditStart(action: () -> Unit) {
        onEditStart = action
    }

    override fun startEdit() {
        super.startEdit()
        onEditStart?.invoke()
    }

    override fun onEditCommit(action: (T?) -> Unit) {
        onEditCommit = action
    }

    override fun commitEdit(newValue: T?) {
        super.commitEdit(newValue)
        onEditCommit?.invoke(newValue)
    }

    override fun onEditCancel(action: () -> Unit) {
        onEditCancel = action
    }

    override fun cancelEdit() {
        super.cancelEdit()
        onEditCancel?.invoke()
    }

    override fun onUpdate(action: (T?, empty: Boolean) -> Unit) {
        onUpdate = action
    }

    override fun updateItem(item: T?, empty: Boolean) {
        super.updateItem(item, empty)
        onUpdate?.invoke(item, empty)
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/layout/FlowPaneTest.kt<|end_filename|>
package ktfx.layouts

import com.hendraanggrian.ktfx.test.LayoutsTest
import javafx.geometry.Orientation
import javafx.scene.layout.FlowPane
import ktfx.controls.insetsOf
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class FlowPaneTest : LayoutsTest<KtfxPane, FlowPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = flowPane { }
    override fun KtfxPane.child2() = flowPane()
    override fun KtfxPane.child3() = flowPane { }

    override fun FlowPane.testDefaultValues() {
        assertEquals(Orientation.HORIZONTAL, orientation)
        assertEquals(0.0, hgap)
        assertEquals(0.0, vgap)
    }

    @Test
    fun margins() {
        flowPane {
            val region1 = region().margin(insetsOf(5))
            assertEquals(5.0, region1.margin!!.top)
            assertEquals(5.0, region1.margin!!.right)
            assertEquals(5.0, region1.margin!!.bottom)
            assertEquals(5.0, region1.margin!!.left)
            val region2 = region().margin(insetsOf(top = 10, right = 20, bottom = 30, left = 40))
            assertEquals(10.0, region2.margin!!.top)
            assertEquals(20.0, region2.margin!!.right)
            assertEquals(30.0, region2.margin!!.bottom)
            assertEquals(40.0, region2.margin!!.left)
            val region3 = region().margin(insetsOf(vertical = 10, horizontal = 20))
            assertEquals(10.0, region3.margin!!.top)
            assertEquals(20.0, region3.margin!!.right)
            assertEquals(10.0, region3.margin!!.bottom)
            assertEquals(20.0, region3.margin!!.left)

            region1.clearConstraints()
            assertNull(region1.margin)
            region2.clearConstraints()
            assertNull(region2.margin)
            region3.clearConstraints()
            assertNull(region3.margin)

            assertEquals(children.size, 3)
        }
    }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_ButtonBar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.ButtonBar
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [ButtonBar] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.buttonBar(buttonOrder: String? = null): ButtonBar = buttonBar(
    buttonOrder =
    buttonOrder
) { }

/**
 * Create a [ButtonBar] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun buttonBar(
    buttonOrder: String? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        KtfxButtonBar
    ).() -> Unit
): ButtonBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxButtonBar(buttonOrder)
    child.configuration()
    return child
}

/**
 * Add a [ButtonBar] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.buttonBar(
    buttonOrder: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxButtonBar).() -> Unit
): ButtonBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxButtonBar(buttonOrder)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [ButtonBar].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledButtonBar(
    buttonOrder: String? = null,
    vararg styleClass: String,
    id: String? = null
): ButtonBar = styledButtonBar(buttonOrder = buttonOrder, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [ButtonBar] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledButtonBar(
    buttonOrder: String? = null,
    vararg styleClass: String,
    id: String? = null
): ButtonBar = styledButtonBar(buttonOrder = buttonOrder, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [ButtonBar] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledButtonBar(
    buttonOrder: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxButtonBar).() -> Unit
): ButtonBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxButtonBar(buttonOrder)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [ButtonBar] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledButtonBar(
    buttonOrder: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxButtonBar).() -> Unit
): ButtonBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxButtonBar(buttonOrder)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/src/ktfx/collections/ObservableArrays.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ObservableArraysKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.collections

import javafx.beans.binding.Bindings
import javafx.beans.binding.IntegerBinding
import javafx.collections.ObservableArray

/**
 * Returns the range of valid indices for the array.
 * @see Array.indices
 */
val ObservableArray<*>.indices: IntRange get() = IntRange(0, lastIndex)

/**
 * Returns the last valid index for the array.
 * @see Array.lastIndex
 */
val ObservableArray<*>.lastIndex: Int get() = size() - 1

/**
 * Returns `true` if the array is empty.
 * @see Array.isEmpty
 */
inline fun ObservableArray<*>.isEmpty(): Boolean = size() == 0

/**
 * Returns `true` if the array is not empty.
 * @see Array.isNotEmpty
 */
inline fun ObservableArray<*>.isNotEmpty(): Boolean = size() != 0

/** Creates a new [IntegerBinding] that contains the size of this array. */
inline val ObservableArray<*>.sizeBinding: IntegerBinding get() = Bindings.size(this)


<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/BindingsIntegerTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.booleanPropertyOf
import ktfx.doublePropertyOf
import ktfx.floatPropertyOf
import ktfx.intPropertyOf
import ktfx.longPropertyOf
import ktfx.propertyOf
import ktfx.time.minutes
import kotlin.test.Test
import kotlin.test.assertEquals

class BindingsIntegerTest {

    @Test
    fun multipleDependencies() {
        val dependency1 = intPropertyOf(1)
        val dependency2 = intPropertyOf(2)
        val binding1 = intBindingOf(dependency1, dependency2) { dependency1.value + dependency2.value }
        assertEquals(3, binding1.value)
        dependency1.value++
        assertEquals(4, binding1.value)

        val dependency3 = intPropertyOf(1)
        val dependency4 = intPropertyOf(2)
        val binding2 = intBindingOf(listOf(dependency3, dependency4)) { dependency3.value + dependency4.value }
        assertEquals(3, binding2.value)
        dependency3.value++
        assertEquals(4, binding2.value)
    }

    @Test
    fun anyDependency() {
        val dependency = propertyOf(1.minutes)
        val binding = dependency.asInt { it?.toMillis()?.toInt() ?: 0 }
        assertEquals(60000, binding.value)
        dependency.value = null
        assertEquals(0, binding.value)
    }

    @Test
    fun booleanDependency() {
        val dependency = booleanPropertyOf()
        val binding = dependency.asInt { if (it) Int.MAX_VALUE else Int.MIN_VALUE }
        assertEquals(Int.MIN_VALUE, binding.value)
        dependency.value = true
        assertEquals(Int.MAX_VALUE, binding.value)
    }

    @Test
    fun doubleDependency() {
        val dependency = doublePropertyOf()
        val binding = dependency.asInt { it.toInt() }
        assertEquals(0, binding.value)
        dependency.value = Double.MAX_VALUE
        assertEquals(Double.MAX_VALUE.toInt(), binding.value)
    }

    @Test
    fun floatDependency() {
        val dependency = floatPropertyOf()
        val binding = dependency.asInt { it.toInt() }
        assertEquals(0, binding.value)
        dependency.value = Float.MAX_VALUE
        assertEquals(Float.MAX_VALUE.toInt(), binding.value)
    }

    @Test
    fun intDependency() {
        val dependency = intPropertyOf()
        val binding = dependency.asInt { it }
        assertEquals(0, binding.value)
        dependency.value = Int.MAX_VALUE
        assertEquals(Int.MAX_VALUE, binding.value)
    }

    @Test
    fun longDependency() {
        val dependency = longPropertyOf()
        val binding = dependency.asInt { it.toInt() }
        assertEquals(0, binding.value)
        dependency.value = Long.MAX_VALUE
        assertEquals(Long.MAX_VALUE.toInt(), binding.value)
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/SVGPathTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.SVGPath
import com.hendraanggrian.ktfx.test.LayoutsTest

class SVGPathTest : LayoutsTest<KtfxPane, SVGPath>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = svgPath { }
    override fun KtfxPane.child2() = svgPath()
    override fun KtfxPane.child3() = svgPath { }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/TreeViewTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.TreeView
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class TreeViewTest : LayoutsTest<KtfxPane, TreeView<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = treeView<String> { }
    override fun KtfxPane.child2() = treeView<String>()
    override fun KtfxPane.child3() = treeView<String> { }

    override fun TreeView<String>.testDefaultValues() {
        assertNull(root)
    }
}

<|start_filename|>ktfx-layouts/src/javafx/scene/KtfxScene.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.scene.layout.Pane
import javafx.scene.paint.Paint
import kotlin.contracts.ExperimentalContracts

/**
 * [Scene] with dynamic-layout dsl support.
 * Invoking dsl will only set its root.
 */
open class KtfxScene(root: Parent, width: Double, height: Double, fill: Paint) :
    Scene(root, width, height, fill), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { root = it as? Pane ?: Pane(it) }
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/PrefixSelectionComboBoxTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.PrefixSelectionComboBox

class PrefixSelectionComboBoxTest : LayoutsTest<KtfxPane, PrefixSelectionComboBox<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = prefixSelectionComboBox<String> { }
    override fun KtfxPane.child2() = prefixSelectionComboBox<String>()
    override fun KtfxPane.child3() = prefixSelectionComboBox<String> { }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_TextFlow.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.text.TextFlow
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [TextFlow] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.textFlow(): TextFlow = textFlow() { }

/**
 * Create a [TextFlow] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun textFlow(configuration: (@KtfxLayoutDslMarker KtfxTextFlow).() -> Unit):
    TextFlow {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTextFlow()
    child.configuration()
    return child
}

/**
 * Add a [TextFlow] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.textFlow(
    configuration: (@KtfxLayoutDslMarker KtfxTextFlow).() ->
    Unit
): TextFlow {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTextFlow()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [TextFlow].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledTextFlow(vararg styleClass: String, id: String? = null): TextFlow =
    styledTextFlow(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [TextFlow] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledTextFlow(vararg styleClass: String, id: String? = null): TextFlow =
    styledTextFlow(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [TextFlow] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledTextFlow(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxTextFlow).() -> Unit
): TextFlow {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTextFlow()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [TextFlow] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledTextFlow(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxTextFlow).() -> Unit
): TextFlow {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTextFlow()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/controls/TransformsTest.kt<|end_filename|>
package ktfx.controls

import com.hendraanggrian.ktfx.test.initToolkit
import javafx.scene.control.Label
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

class TransformsTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun affine() {
        val transformation = Label().affineTransformation {
            mxx = 1.0
            mxy = 2.0
            mxz = 3.0
        }
        assertEquals(1.0, transformation.mxx)
        assertEquals(2.0, transformation.mxy)
        assertEquals(3.0, transformation.mxz)
    }

    @Test
    fun rotate() {
        val transformation = Label().rotateTransformation {
            pivotX = 1.0
            pivotY = 2.0
            pivotZ = 3.0
        }
        assertEquals(1.0, transformation.pivotX)
        assertEquals(2.0, transformation.pivotY)
        assertEquals(3.0, transformation.pivotZ)
    }

    @Test
    fun scale() {
        val transformation = Label().scaleTransformation {
            pivotX = 1.0
            pivotY = 2.0
            pivotZ = 3.0
        }
        assertEquals(1.0, transformation.pivotX)
        assertEquals(2.0, transformation.pivotY)
        assertEquals(3.0, transformation.pivotZ)
    }

    @Test
    fun shear() {
        val transformation = Label().shearTransformation {
            pivotX = 1.0
            pivotY = 2.0
        }
        assertEquals(1.0, transformation.pivotX)
        assertEquals(2.0, transformation.pivotY)
    }

    @Test
    fun translate() {
        val transformation = Label().translateTransformation {
            x = 1.0
            y = 2.0
            z = 3.0
        }
        assertEquals(1.0, transformation.x)
        assertEquals(2.0, transformation.y)
        assertEquals(3.0, transformation.z)
    }
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_MenuButton.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.MenuButton
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [MenuButton] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.menuButton(text: String? = null, graphic: Node? = null): MenuButton =
    menuButton(text = text, graphic = graphic) { }

/**
 * Create a [MenuButton] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun menuButton(
    text: String? = null,
    graphic: Node? = null,
    configuration: (@KtfxLayoutDslMarker KtfxMenuButton).() -> Unit
): MenuButton {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxMenuButton(text, graphic)
    child.configuration()
    return child
}

/**
 * Add a [MenuButton] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.menuButton(
    text: String? = null,
    graphic: Node? = null,
    configuration: (@KtfxLayoutDslMarker KtfxMenuButton).() -> Unit
): MenuButton {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxMenuButton(text, graphic)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [MenuButton].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledMenuButton(
    text: String? = null,
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null
): MenuButton = styledMenuButton(text = text, graphic = graphic, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [MenuButton] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledMenuButton(
    text: String? = null,
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null
): MenuButton = styledMenuButton(text = text, graphic = graphic, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [MenuButton] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledMenuButton(
    text: String? = null,
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxMenuButton).() -> Unit
): MenuButton {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxMenuButton(text, graphic)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [MenuButton] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledMenuButton(
    text: String? = null,
    graphic: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxMenuButton).() -> Unit
): MenuButton {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxMenuButton(text, graphic)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/text/StringConverterTest.kt<|end_filename|>
package ktfx.text

import javafx.util.Duration
import javafx.util.converter.DefaultStringConverter
import javafx.util.converter.IntegerStringConverter
import ktfx.time.milliseconds
import ktfx.time.toDuration
import kotlin.test.Test
import kotlin.test.assertEquals

class StringConverterTest {
    private val defaultConverter = DefaultStringConverter()
    private val intConverter = IntegerStringConverter()

    @Test
    fun buildStringConverter() {
        val converter = buildStringConverter<Duration> {
            toString { it!!.toString() }
            fromString { it.toDuration() }
        }
        assertEquals(converter.toString(1.milliseconds), "1.0 ms")
        assertEquals(converter.fromString("1.0ms"), 1.milliseconds)

        val primitiveConverter = buildStringConverter<Int> {
            fromString { it.toInt() }
        }
        assertEquals(primitiveConverter.toString(123), "123")
        assertEquals(primitiveConverter.fromString("123"), 123)
    }

    @Test
    fun invoke() {
        assertEquals(intConverter.toString(123), intConverter(123))
        assertEquals(defaultConverter.toString(null), defaultConverter(null))
    }

    @Test
    fun get() {
        assertEquals(intConverter.fromString("123"), intConverter["123"])
        assertEquals(defaultConverter.fromString("Hello world"), defaultConverter["Hello world"])
    }
}


<|start_filename|>ktfx-commons/tests/src/ktfx/ObservableValueTest.kt<|end_filename|>
package ktfx

import ktfx.time.minutes
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNull
import kotlin.test.assertTrue

class ObservableValueTest {
    private val objectProperty = propertyOf<javafx.util.Duration>()
    private var `object` by objectProperty

    @Test
    fun `object`() {
        assertNull(`object`)
        `object` = 2.minutes
        assertEquals(2.minutes, objectProperty.value)
    }

    private val stringProperty = stringPropertyOf()
    private var string by stringProperty

    @Test
    fun string() {
        assertNull(string)
        string = "Hello World"
        assertEquals("Hello World", stringProperty.value)
    }

    private val booleanProperty = booleanPropertyOf()
    private var boolean by booleanProperty

    @Test
    fun boolean() {
        assertFalse(boolean)
        boolean = true
        assertTrue(booleanProperty.value)
    }

    private val doubleProperty = doublePropertyOf()
    private var double by doubleProperty

    @Test
    fun double() {
        assertEquals(0.0, double)
        double = Double.MAX_VALUE
        assertEquals(Double.MAX_VALUE, doubleProperty.value)
    }

    private val floatProperty = floatPropertyOf()
    private var float by floatProperty

    @Test
    fun float() {
        assertEquals(0f, float)
        float = Float.MAX_VALUE
        assertEquals(Float.MAX_VALUE, floatProperty.value)
    }

    private val longProperty = longPropertyOf()
    private var long by longProperty

    @Test
    fun long() {
        assertEquals(0L, long)
        long = Long.MAX_VALUE
        assertEquals(Long.MAX_VALUE, longProperty.value)
    }

    private val intProperty = intPropertyOf()
    private var int by intProperty

    @Test
    fun int() {
        assertEquals(0, int)
        int = Int.MAX_VALUE
        assertEquals(Int.MAX_VALUE, intProperty.value)
    }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/controls/AnimationsTest.kt<|end_filename|>
package ktfx.controls

import com.hendraanggrian.ktfx.test.initToolkit
import javafx.animation.FadeTransition
import javafx.animation.FillTransition
import javafx.scene.control.Label
import javafx.scene.shape.Rectangle
import ktfx.time.milliseconds
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class AnimationsTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun fadeTransition() {
        val node = Label()
        val transition = node.fadeTransition { }
        assertEquals(node, transition.node)
        assertEquals(400.milliseconds, transition.duration)
    }

    @Test
    fun fillTransition() {
        val shape = Rectangle()
        val transition = shape.fillTransition { }
        assertEquals(shape, transition.shape)
        assertEquals(400.milliseconds, transition.duration)
    }

    @Test
    fun pathTransition() {
        val node = Label()
        val transition = node.pathTransition { }
        assertEquals(node, transition.node)
        assertEquals(400.milliseconds, transition.duration)
    }

    @Test
    fun rotateTransition() {
        val node = Label()
        val transition = node.rotateTransition { }
        assertEquals(node, transition.node)
        assertEquals(400.milliseconds, transition.duration)
    }

    @Test
    fun scaleTransition() {
        val node = Label()
        val transition = node.scaleTransition { }
        assertEquals(node, transition.node)
        assertEquals(400.milliseconds, transition.duration)
    }

    @Test
    fun strokeTransition() {
        val shape = Rectangle()
        val transition = shape.strokeTransition { }
        assertEquals(shape, transition.shape)
        assertEquals(400.milliseconds, transition.duration)
    }

    @Test
    fun translateTransition() {
        val node = Label()
        val transition = node.translateTransition { }
        assertEquals(node, transition.node)
        assertEquals(400.milliseconds, transition.duration)
    }

    @Test
    fun parallelTransition() {
        val node = Label()
        val transition = node.parallelTransition {
            fade { }
        }
        assertEquals(node, transition.node)
        assertTrue(transition.children.first() is FadeTransition)
    }

    @Test
    fun shapeParallelTransition() {
        val shape = Rectangle()
        val transition = shape.shapeParallelTransition {
            fill { }
        }
        assertEquals(shape, transition.node)
        assertTrue(transition.children.first() is FillTransition)
    }

    @Test
    fun sequentialTransition() {
        val node = Label()
        val transition = node.sequentialTransition {
            fade { }
        }
        assertEquals(node, transition.node)
        assertTrue(transition.children.first() is FadeTransition)
    }

    @Test
    fun shapeSequentialTransition() {
        val shape = Rectangle()
        val transition = shape.shapeSequentialTransition {
            fill { }
        }
        assertEquals(shape, transition.node)
        assertTrue(transition.children.first() is FillTransition)
    }
}


<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXTreeCell.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTreeCell
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXTreeCell] to this manager.
 *
 * @return the control added.
 */
public fun <T> NodeManager.jfxTreeCell(): JFXTreeCell<T> = jfxTreeCell() { }

/**
 * Create a [JFXTreeCell] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun <T> jfxTreeCell(configuration: (@KtfxLayoutDslMarker JFXTreeCell<T>).() -> Unit):
    JFXTreeCell<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXTreeCell<T>()
    child.configuration()
    return child
}

/**
 * Add a [JFXTreeCell] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun <T> NodeManager.jfxTreeCell(
    configuration: (
        @KtfxLayoutDslMarker
        JFXTreeCell<T>
    ).() -> Unit
): JFXTreeCell<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXTreeCell<T>()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXTreeCell].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun <T> styledJFXTreeCell(vararg styleClass: String, id: String? = null): JFXTreeCell<T> =
    styledJFXTreeCell(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXTreeCell] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun <T> NodeManager.styledJFXTreeCell(vararg styleClass: String, id: String? = null):
    JFXTreeCell<T> = styledJFXTreeCell(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [JFXTreeCell] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun <T> styledJFXTreeCell(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXTreeCell<T>).() -> Unit
): JFXTreeCell<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXTreeCell<T>()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXTreeCell] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun <T> NodeManager.styledJFXTreeCell(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXTreeCell<T>).() -> Unit
): JFXTreeCell<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXTreeCell<T>()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_Window.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.stage.Window
import javafx.stage.WindowEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Window.setOnCloseRequest
 */
public fun Window.onCloseRequest(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WindowEvent) -> Unit
) {
    return setOnCloseRequest { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Window.setOnShowing
 */
public fun Window.onShowing(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WindowEvent) -> Unit
) {
    return setOnShowing { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Window.setOnShown
 */
public fun Window.onShown(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WindowEvent) -> Unit
) {
    return setOnShown { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Window.setOnHiding
 */
public fun Window.onHiding(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WindowEvent) -> Unit
) {
    return setOnHiding { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Window.setOnHidden
 */
public fun Window.onHidden(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WindowEvent) -> Unit
) {
    return setOnHidden { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Canvas.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.canvas.Canvas
import kotlin.Double
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [Canvas] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.canvas(width: Double = 0.0, height: Double = 0.0): Canvas = canvas(
    width =
    width,
    height = height
) { }

/**
 * Create a [Canvas] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun canvas(
    width: Double = 0.0,
    height: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker Canvas).() -> Unit
): Canvas {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Canvas(width, height)
    child.configuration()
    return child
}

/**
 * Add a [Canvas] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.canvas(
    width: Double = 0.0,
    height: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker Canvas).() -> Unit
): Canvas {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Canvas(width, height)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Canvas].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledCanvas(
    width: Double = 0.0,
    height: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): Canvas = styledCanvas(width = width, height = height, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [Canvas] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledCanvas(
    width: Double = 0.0,
    height: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): Canvas = styledCanvas(width = width, height = height, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [Canvas] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledCanvas(
    width: Double = 0.0,
    height: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Canvas).() -> Unit
): Canvas {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Canvas(width, height)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Canvas] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledCanvas(
    width: Double = 0.0,
    height: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Canvas).() -> Unit
): Canvas {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Canvas(width, height)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_VLineTo.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.VLineTo
import kotlin.Double
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [VLineTo] to this manager.
 *
 * @return the control added.
 */
public fun PathElementManager.vlineTo(y: Double = 0.0): VLineTo = vlineTo(y = y) { }

/**
 * Create a [VLineTo] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun vlineTo(
    y: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker VLineTo).() ->    
    Unit
): VLineTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = VLineTo(y)
    child.configuration()
    return child
}

/**
 * Add a [VLineTo] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun PathElementManager.vlineTo(
    y: Double = 0.0,
    configuration: (
        @KtfxLayoutDslMarker    
        VLineTo
    ).() -> Unit
): VLineTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = VLineTo(y)
    child.configuration()
    return addChild(child)
}


<|start_filename|>rulesets/layouts/tests/src/com/hendraanggrian/ktfx/rules/OpenClassRuleTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.hendraanggrian.ktfx.test.RuleTest
import kotlin.test.Test

class OpenClassRuleTest : RuleTest {
    override val rule = OpenClassRule()

    @Test
    fun test() = assertRule(
        lintErrorOf(1, 1, "Empty modifiers, need open."),
        lintErrorOf(5, 8, "Public classes need open modifier.")
    ) {
        """
            class Failing
            open class Correct
            private class Correct2
            internal class Correct3
            actual class Failing2
        """
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_StatusBar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.StatusBar
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [StatusBar] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.statusBar(): StatusBar = statusBar() { }

/**
 * Create a [StatusBar] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun statusBar(configuration: (@KtfxLayoutDslMarker StatusBar).() -> Unit): StatusBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = StatusBar()
    child.configuration()
    return child
}

/**
 * Add a [StatusBar] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.statusBar(configuration: (@KtfxLayoutDslMarker StatusBar).() -> Unit):
    StatusBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = StatusBar()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [StatusBar].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledStatusBar(vararg styleClass: String, id: String? = null): StatusBar =
    styledStatusBar(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [StatusBar] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledStatusBar(vararg styleClass: String, id: String? = null): StatusBar =
    styledStatusBar(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [StatusBar] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledStatusBar(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker StatusBar).() -> Unit
): StatusBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = StatusBar()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [StatusBar] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledStatusBar(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker StatusBar).() -> Unit
): StatusBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = StatusBar()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXMasonryPaneTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXMasonryPane
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXMasonryPaneTest : LayoutsTest<KtfxPane, JFXMasonryPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxMasonryPane { }
    override fun KtfxPane.child2() = jfxMasonryPane()
    override fun KtfxPane.child3() = jfxMasonryPane { }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXButtonTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXButton
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class JFXButtonTest : LayoutsTest<KtfxPane, JFXButton>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxButton { }
    override fun KtfxPane.child2() = jfxButton()
    override fun KtfxPane.child3() = jfxButton { }

    override fun JFXButton.testDefaultValues() {
        assertNull(text)
        assertNull(graphic)
    }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/controls/InsetsTest.kt<|end_filename|>
package ktfx.controls

import com.hendraanggrian.ktfx.test.initToolkit
import javafx.scene.layout.Region
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

class InsetsTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun insetsOf() {
        val region = Region()
        region.padding = insetsOf(10)
        assertEquals(10.0, region.padding.top)
        assertEquals(10.0, region.padding.right)
        assertEquals(10.0, region.padding.bottom)
        assertEquals(10.0, region.padding.left)
        region.padding = insetsOf(top = 15)
        assertEquals(15.0, region.padding.top)
        region.padding = insetsOf(left = 20)
        assertEquals(20.0, region.padding.left)
        region.padding = insetsOf(right = 25)
        assertEquals(25.0, region.padding.right)
        region.padding = insetsOf(bottom = 30)
        assertEquals(30.0, region.padding.bottom)
        region.padding = insetsOf(horizontal = 35)
        assertEquals(35.0, region.padding.left)
        assertEquals(35.0, region.padding.right)
        region.padding = insetsOf(vertical = 40)
        assertEquals(40.0, region.padding.top)
        assertEquals(40.0, region.padding.bottom)
    }
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/NotificationPaneTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.NotificationPane

class NotificationPaneTest : LayoutsTest<KtfxPane, NotificationPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = notificationPane { }
    override fun KtfxPane.child2() = notificationPane()
    override fun KtfxPane.child3() = notificationPane { }
}

<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/dialogs/LoginDialogsTest.kt<|end_filename|>
package ktfx.controlsfx.dialogs

import com.hendraanggrian.ktfx.test.DialogShowingTest
import ktfx.toFxPair
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class LoginDialogsTest : DialogShowingTest() {

    private val userInfo = "Hello" to "World"

    @Test
    fun exceptionDialog() {
        interact {
            assertEquals(
                userInfo.toFxPair(),
                loginDialog("Login dialog", sampleGraphic, userInfo, {}) {
                    closeOnShow(this)
                    assertEquals("Login dialog", headerText)
                    assertEquals(sampleGraphic, graphic)
                }.get()
            )
            assertEquals(userInfo.toFxPair(), loginDialog(userInfo, {}) { closeOnShow(this) }.get())
        }
    }
}

<|start_filename|>rulesets/basic/src/com/hendraanggrian/ktfx/rules/NoGetterPropertyStaticImportRule.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.pinterest.ktlint.core.Rule
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.psi.KtAnnotationEntry
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
import org.jetbrains.kotlin.psi.KtPropertyAccessor
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes

/** Mutable property with no getter should static import all members and declaration. */
class NoGetterPropertyStaticImportRule : Rule("no-getter-property-static-import") {

    override fun visit(node: ASTNode, autoCorrect: Boolean, emit: (Int, String, Boolean) -> Unit) {
        if (node.elementType != KtStubElementTypes.ANNOTATION_ENTRY) {
            return
        }
        val ktAnnotationEntry = node.getPsi(KtAnnotationEntry::class.java)
            .takeIf { it.shortName?.asString() == "Deprecated" }
            ?: return

        // check members
        ktAnnotationEntry.valueArguments
            .mapNotNull { it.asElement().firstChild as? KtDotQualifiedExpression }
            .takeIf { it.isNotEmpty() }
            ?.let { emit(it.first().startOffset, "Annotation members should static import", false) }
        // check declaration
        ktAnnotationEntry.getParentOfType<KtPropertyAccessor>(true)
            ?.bodyExpression
            ?.takeIf { it is KtDotQualifiedExpression }
            ?.let { emit(it.startOffset, "Declaration should static import", false) }
    }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/media/MediaViewTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.media.MediaErrorEvent
import javafx.scene.media.MediaView
import com.hendraanggrian.ktfx.test.BaseMediaViewTest

class MediaViewTest : BaseMediaViewTest() {

    override fun MediaView.callOnError(action: (MediaErrorEvent) -> Unit) = onError(action)
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/BindingsObject.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("BindingsKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.Observable
import javafx.beans.binding.Bindings
import javafx.beans.binding.ObjectBinding
import javafx.beans.value.ObservableBooleanValue
import javafx.beans.value.ObservableDoubleValue
import javafx.beans.value.ObservableFloatValue
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableLongValue
import javafx.beans.value.ObservableObjectValue
import javafx.collections.ObservableList
import javafx.collections.ObservableMap
import javafx.collections.ObservableSet
import ktfx.collections.observableListOf
import ktfx.collections.toObservableList
import java.util.concurrent.Callable

/** Create an [ObjectBinding] with multiple [Observable] dependencies. */
inline fun <T> bindingOf(vararg dependencies: Observable, noinline valueProvider: () -> T?): ObjectBinding<T> =
    Bindings.createObjectBinding<T>(Callable(valueProvider), *dependencies)

/** Create a [ObjectBinding] with multiple [Observable] dependencies using collection. */
fun <T> bindingOf(dependencies: Collection<Observable>, valueProvider: () -> T?): ObjectBinding<T> =
    bindingOf(*dependencies.toTypedArray(), valueProvider = valueProvider)

/** Create an [ObjectBinding] with single [ObservableList] dependency. */
fun <E, T> ObservableList<E>.asAny(valueProvider: (List<E>) -> T?): ObjectBinding<T> =
    object : ObjectBinding<T>() {
        override fun dispose(): Unit = unbind(this@asAny)
        override fun computeValue(): T? = valueProvider(this@asAny)
        override fun getDependencies(): ObservableList<*> = this@asAny

        init {
            bind(this@asAny)
        }
    }

/** Create an [ObjectBinding] with single [ObservableSet] dependency. */
fun <E, T> ObservableSet<E>.asAny(valueProvider: (Set<E>) -> T?): ObjectBinding<T> =
    object : ObjectBinding<T>() {
        override fun dispose(): Unit = unbind(this@asAny)
        override fun computeValue(): T? = valueProvider(this@asAny)
        override fun getDependencies(): ObservableList<*> = this@asAny.toObservableList()

        init {
            bind(this@asAny)
        }
    }

/** Create an [ObjectBinding] with single [ObservableMap] dependency. */
fun <K, V, T> ObservableMap<K, V>.asAny(valueProvider: (Map<K, V>) -> T?): ObjectBinding<T> =
    object : ObjectBinding<T>() {
        override fun dispose(): Unit = unbind(this@asAny)
        override fun computeValue(): T? = valueProvider(this@asAny)
        override fun getDependencies(): ObservableList<*> = this@asAny.keys.toObservableList()

        init {
            bind(this@asAny)
        }
    }

/** Create an [ObjectBinding] with single [ObservableObjectValue] dependency. */
fun <V, T> ObservableObjectValue<V>.asAny(valueProvider: (V?) -> T?): ObjectBinding<T> =
    object : ObjectBinding<T>() {
        override fun dispose(): Unit = unbind(this@asAny)
        override fun computeValue(): T? = valueProvider(this@asAny.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asAny)

        init {
            bind(this@asAny)
        }
    }

/** Create an [ObjectBinding] with single [ObservableBooleanValue] dependency. */
fun <T> ObservableBooleanValue.asAny(valueProvider: (Boolean) -> T?): ObjectBinding<T> =
    object : ObjectBinding<T>() {
        override fun dispose(): Unit = unbind(this@asAny)
        override fun computeValue(): T? = valueProvider(this@asAny.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asAny)

        init {
            bind(this@asAny)
        }
    }

/** Create an [ObjectBinding] with single [ObservableDoubleValue] dependency. */
fun <T> ObservableDoubleValue.asAny(valueProvider: (Double) -> T?): ObjectBinding<T> =
    object : ObjectBinding<T>() {
        override fun dispose(): Unit = unbind(this@asAny)
        override fun computeValue(): T? = valueProvider(this@asAny.value as Double)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asAny)

        init {
            bind(this@asAny)
        }
    }

/** Create an [ObjectBinding] with single [ObservableFloatValue] dependency. */
fun <T> ObservableFloatValue.asAny(valueProvider: (Float) -> T?): ObjectBinding<T> =
    object : ObjectBinding<T>() {
        override fun dispose(): Unit = unbind(this@asAny)
        override fun computeValue(): T? = valueProvider(this@asAny.value as Float)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asAny)

        init {
            bind(this@asAny)
        }
    }

/** Create an [ObjectBinding] with single [ObservableIntegerValue] dependency. */
fun <T> ObservableIntegerValue.asAny(valueProvider: (Int) -> T?): ObjectBinding<T> =
    object : ObjectBinding<T>() {
        override fun dispose(): Unit = unbind(this@asAny)
        override fun computeValue(): T? = valueProvider(this@asAny.value as Int)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asAny)

        init {
            bind(this@asAny)
        }
    }

/** Create an [ObjectBinding] with single [ObservableLongValue] dependency. */
fun <T> ObservableLongValue.asAny(valueProvider: (Long) -> T?): ObjectBinding<T> =
    object : ObjectBinding<T>() {
        override fun dispose(): Unit = unbind(this@asAny)
        override fun computeValue(): T? = valueProvider(this@asAny.value as Long)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asAny)

        init {
            bind(this@asAny)
        }
    }


<|start_filename|>settings.gradle.kts<|end_filename|>
include("ktfx-commons")
include("ktfx-layouts")
include("ktfx-listeners")
include("ktfx-coroutines")
include("ktfx")

includeDir("thirdparty")
includeDir("rulesets")
includeDir("testing")

include("codegen")
include("website")
include("sample")

fun includeDir(dir: String) = file(dir)
    .listFiles()!!
    .filter { it.isDirectory }
    .forEach { include("$dir:${it.name}") }

<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/CheckComboBoxTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import com.google.common.truth.Truth.assertThat
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.CheckComboBox

class CheckComboBoxTest : LayoutsTest<KtfxPane, CheckComboBox<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = checkComboBox<String> { }
    override fun KtfxPane.child2() = checkComboBox<String>()
    override fun KtfxPane.child3() = checkComboBox<String> { }

    override fun CheckComboBox<String>.testDefaultValues() {
        assertThat(items).isEmpty()
    }
}

<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_TreeTableView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.TreeTableColumn
import javafx.scene.control.TreeTableView
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Int
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see TreeTableView.setOnSort
 */
public fun <T> TreeTableView<T>.onSort(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(SortEvent<TreeTableView<T>>) -> Unit
) {
    return setOnSort { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TreeTableView.setOnScrollTo
 */
public fun <T> TreeTableView<T>.onScrollTo(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ScrollToEvent<Int>) -> Unit
) {
    return setOnScrollTo { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TreeTableView.setOnScrollToColumn
 */
public fun <T> TreeTableView<T>.onScrollToColumn(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ScrollToEvent<TreeTableColumn<T, *>>) -> Unit
) {
    return setOnScrollToColumn { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>thirdparty/controlsfx-listeners/tests/src/org/controlsfx/control/NotificationPaneTest.kt<|end_filename|>
package ktfx.controlsfx.listeners

import javafx.event.Event
import ktfx.controlsfx.test.BaseNotificationPaneTest
import org.controlsfx.control.NotificationPane

class NotificationPaneTest : BaseNotificationPaneTest() {

    override fun NotificationPane.callOnShowing(action: (Event) -> Unit) = onShowing(action)
    override fun NotificationPane.callOnShown(action: (Event) -> Unit) = onShown(action)
    override fun NotificationPane.callOnHiding(action: (Event) -> Unit) = onHiding(action)
    override fun NotificationPane.callOnHidden(action: (Event) -> Unit) = onHidden(action)
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/SceneTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.BaseSceneTest
import javafx.scene.Scene
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent
import kotlinx.coroutines.Dispatchers

class SceneTest : BaseSceneTest() {

    override fun Scene.callOnMouseClicked(action: (MouseEvent) -> Unit) =
        onMouseClicked(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnMouseDragged(action: (MouseEvent) -> Unit) =
        onMouseDragged(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnMouseEntered(action: (MouseEvent) -> Unit) =
        onMouseEntered(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnMouseExited(action: (MouseEvent) -> Unit) =
        onMouseExited(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnMouseMoved(action: (MouseEvent) -> Unit) =
        onMouseMoved(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnMousePressed(action: (MouseEvent) -> Unit) =
        onMousePressed(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnMouseReleased(action: (MouseEvent) -> Unit) =
        onMouseReleased(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnDragDetected(action: (MouseEvent) -> Unit) =
        onDragDetected(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnMouseDragOver(action: (MouseDragEvent) -> Unit) =
        onMouseDragOver(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnMouseDragReleased(action: (MouseDragEvent) -> Unit) =
        onMouseDragReleased(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnMouseDragEntered(action: (MouseDragEvent) -> Unit) =
        onMouseDragEntered(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnMouseDragExited(action: (MouseDragEvent) -> Unit) =
        onMouseDragExited(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnScrollStarted(action: (ScrollEvent) -> Unit) =
        onScrollStarted(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnScroll(action: (ScrollEvent) -> Unit) =
        onScroll(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnScrollFinished(action: (ScrollEvent) -> Unit) =
        onScrollFinished(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnRotationStarted(action: (RotateEvent) -> Unit) =
        onRotationStarted(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnRotate(action: (RotateEvent) -> Unit) =
        onRotate(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnRotationFinished(action: (RotateEvent) -> Unit) =
        onRotationFinished(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnZoomStarted(action: (ZoomEvent) -> Unit) =
        onZoomStarted(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnZoom(action: (ZoomEvent) -> Unit) =
        onZoom(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnZoomFinished(action: (ZoomEvent) -> Unit) =
        onZoomFinished(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnSwipeUp(action: (SwipeEvent) -> Unit) =
        onSwipeUp(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnSwipeDown(action: (SwipeEvent) -> Unit) =
        onSwipeDown(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnSwipeRight(action: (SwipeEvent) -> Unit) =
        onSwipeRight(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnSwipeLeft(action: (SwipeEvent) -> Unit) =
        onSwipeLeft(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnTouchPressed(action: (TouchEvent) -> Unit) =
        onTouchPressed(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnTouchMoved(action: (TouchEvent) -> Unit) =
        onTouchMoved(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnTouchReleased(action: (TouchEvent) -> Unit) =
        onTouchReleased(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnTouchStationary(action: (TouchEvent) -> Unit) =
        onTouchStationary(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnDragEntered(action: (DragEvent) -> Unit) =
        onDragEntered(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnDragExited(action: (DragEvent) -> Unit) =
        onDragExited(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnDragOver(action: (DragEvent) -> Unit) =
        onDragOver(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnDragDropped(action: (DragEvent) -> Unit) =
        onDragDropped(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnDragDone(action: (DragEvent) -> Unit) =
        onDragDone(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnKeyPressed(action: (KeyEvent) -> Unit) =
        onKeyPressed(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnKeyReleased(action: (KeyEvent) -> Unit) =
        onKeyReleased(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnKeyTyped(action: (KeyEvent) -> Unit) =
        onKeyTyped(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnInputMethodTextChanged(action: (InputMethodEvent) -> Unit) =
        onInputMethodTextChanged(Dispatchers.Unconfined) { action(it) }

    override fun Scene.callOnContextMenuRequested(action: (ContextMenuEvent) -> Unit) =
        onContextMenuRequested(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Tab.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.Tab
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [Tab] to this manager.
 *
 * @return the control added.
 */
public fun TabManager.tab(text: String? = null, content: Node? = null): Tab = tab(
    text = text,
    content = content
) { }

/**
 * Create a [Tab] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun tab(
    text: String? = null,
    content: Node? = null,
    configuration: (@KtfxLayoutDslMarker KtfxTab).() -> Unit
): Tab {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTab(text, content)
    child.configuration()
    return child
}

/**
 * Add a [Tab] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun TabManager.tab(
    text: String? = null,
    content: Node? = null,
    configuration: (@KtfxLayoutDslMarker KtfxTab).() -> Unit
): Tab {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTab(text, content)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Tab].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledTab(
    text: String? = null,
    content: Node? = null,
    vararg styleClass: String,
    id: String? = null
): Tab = styledTab(text = text, content = content, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [Tab] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun TabManager.styledTab(
    text: String? = null,
    content: Node? = null,
    vararg styleClass: String,
    id: String? = null
): Tab = styledTab(text = text, content = content, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [Tab] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledTab(
    text: String? = null,
    content: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxTab).() -> Unit
): Tab {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTab(text, content)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Tab] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun TabManager.styledTab(
    text: String? = null,
    content: Node? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxTab).() -> Unit
): Tab {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxTab(text, content)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>testing/listeners-coroutines-controlsfx/src/org/controlsfx/control/BaseBreadCrumbBarTest.kt<|end_filename|>
package ktfx.controlsfx.test

import com.hendraanggrian.ktfx.test.initToolkit
import org.controlsfx.control.BreadCrumbBar
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseBreadCrumbBarTest {
    private lateinit var crumbBar: BreadCrumbBar<String>

    abstract fun <E> BreadCrumbBar<E>.callOnCrumbAction(action: (BreadCrumbBar.BreadCrumbActionEvent<E>) -> Unit)

    @BeforeTest
    fun create() {
        initToolkit()
        crumbBar = BreadCrumbBar()
    }

    @Test
    fun onCrumbAction() {
        crumbBar.callOnCrumbAction {
            assertEquals("Hello world", it.selectedCrumb.value)
        }
        crumbBar.onCrumbAction.handle(BreadCrumbBar.BreadCrumbActionEvent(BreadCrumbBar.buildTreeModel("Hello world")))
    }
}

<|start_filename|>thirdparty/controlsfx-listeners/tests/src/org/controlsfx/control/BreadCrumbBarTest.kt<|end_filename|>
package ktfx.controlsfx.listeners

import ktfx.controlsfx.test.BaseBreadCrumbBarTest
import org.controlsfx.control.BreadCrumbBar

class BreadCrumbBarTest : BaseBreadCrumbBarTest() {

    override fun <E> BreadCrumbBar<E>.callOnCrumbAction(action: (BreadCrumbBar.BreadCrumbActionEvent<E>) -> Unit) =
        onCrumbAction(action)
}

<|start_filename|>testing/listeners-coroutines/src/javafx/beans/value/BaseObservableValueTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.beans.Observable
import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty
import javafx.beans.value.ObservableValue
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue

abstract class BaseObservableValueTest {

    abstract fun ObservableValue<String>.callListener(action: (Observable, String, String) -> Unit)

    @Test
    fun listen() {
        val property = SimpleStringProperty()
        property.callListener { observable, oldValue, value ->
            assertTrue(observable is StringProperty)
            assertNull(oldValue)
            assertEquals("Hello world", value)
        }
        property.set("Hello world")
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/beans/BaseObservableTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.beans.Observable
import javafx.beans.property.SimpleStringProperty
import javafx.beans.property.StringProperty
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

abstract class BaseObservableTest {

    abstract fun Observable.callListener(action: (Observable) -> Unit)

    @Test
    fun listener() {
        val property = SimpleStringProperty()
        property.callListener {
            assertTrue(it is StringProperty)
            assertEquals("Hello world", it.get())
        }
        property.set("Hello world")
    }
}

<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_Dialog.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.control.Dialog
import javafx.scene.control.DialogEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Dialog.setOnShowing
 */
public fun Dialog<*>.onShowing(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DialogEvent) -> Unit
) {
    return setOnShowing { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Dialog.setOnShown
 */
public fun Dialog<*>.onShown(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DialogEvent) -> Unit
) {
    return setOnShown { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Dialog.setOnHiding
 */
public fun Dialog<*>.onHiding(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DialogEvent) -> Unit
) {
    return setOnHiding { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Dialog.setOnHidden
 */
public fun Dialog<*>.onHidden(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DialogEvent) -> Unit
) {
    return setOnHidden { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Dialog.setOnCloseRequest
 */
public fun Dialog<*>.onCloseRequest(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DialogEvent) -> Unit
) {
    return setOnCloseRequest { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_SnapshotView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.SnapshotView
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [SnapshotView] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.snapshotView(): SnapshotView = snapshotView() { }

/**
 * Create a [SnapshotView] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun snapshotView(configuration: (@KtfxLayoutDslMarker KtfxSnapshotView).() -> Unit):
    SnapshotView {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxSnapshotView()
    child.configuration()
    return child
}

/**
 * Add a [SnapshotView] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.snapshotView(
    configuration: (
        @KtfxLayoutDslMarker
        KtfxSnapshotView
    ).() -> Unit
): SnapshotView {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxSnapshotView()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [SnapshotView].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledSnapshotView(vararg styleClass: String, id: String? = null): SnapshotView =
    styledSnapshotView(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [SnapshotView] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledSnapshotView(vararg styleClass: String, id: String? = null):
    SnapshotView = styledSnapshotView(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [SnapshotView] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledSnapshotView(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxSnapshotView).() -> Unit
): SnapshotView {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxSnapshotView()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [SnapshotView] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledSnapshotView(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxSnapshotView).() -> Unit
): SnapshotView {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxSnapshotView()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>rulesets/basic/tests/src/com/hendraanggrian/ktfx/rules/NotNullAssertionOperatorRuleTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.hendraanggrian.ktfx.test.RuleTest
import kotlin.test.Test

class NotNullAssertionOperatorRuleTest : RuleTest {
    override val rule = NotNullAssertionOperatorRule()

    @Test
    fun function() = assertRule(
        lintErrorOf(2, 35, "Replace `!!` with `checkNotNull` with helpful message")
    ) {
        """
            fun function() {
                val something = getSomething()!!
            }
        """
    }

    @Test
    fun expressionFunction() = assertRule(
        lintErrorOf(1, 37, "Replace `!!` with `checkNotNull` with helpful message")
    ) {
        """
            fun expressionFunction() = getItem()!!
        """
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/org/controlsfx/control/KtfxSnapshotView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import javafx.scene.Node
import ktfx.layouts.NodeManager
import org.controlsfx.control.SnapshotView
import kotlin.contracts.ExperimentalContracts

/**
 * [SnapshotView] with dynamic-layout dsl support.
 * Invoking dsl will only set its node.
 */
open class KtfxSnapshotView : SnapshotView(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { this.node = it }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ProgressIndicatorTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.ProgressBar
import javafx.scene.control.ProgressIndicator
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class ProgressIndicatorTest : LayoutsTest<KtfxPane, ProgressIndicator>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = progressIndicator { }
    override fun KtfxPane.child2() = progressIndicator()
    override fun KtfxPane.child3() = progressIndicator { }

    override fun ProgressIndicator.testDefaultValues() {
        assertEquals(ProgressBar.INDETERMINATE_PROGRESS, progress)
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseTreeTableViewTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.TreeTableColumn
import javafx.scene.control.TreeTablePosition
import javafx.scene.control.TreeTableView
import javafx.util.Duration
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseTreeTableViewTest {
    private lateinit var table: TreeTableView<Duration>
    private lateinit var column: TreeTableColumn<Duration, Long>
    private lateinit var position: TreeTablePosition<Duration, Long>

    abstract fun <S> TreeTableView<S>.callOnSort(action: (SortEvent<TreeTableView<S>>) -> Unit)
    abstract fun <S> TreeTableView<S>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit)
    abstract fun <S> TreeTableView<S>.callOnScrollToColumn(action: (ScrollToEvent<TreeTableColumn<S, *>>) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        table = TreeTableView()
        table.columns += TreeTableColumn<Duration, Long>().also { column = it }
        position = TreeTablePosition(table, 0, column)
    }

    @Test
    fun onSort() {
        table.callOnSort {
            assertEquals(table, it.source)
            assertEquals(FakeEventTarget, it.target)
        }
        table.onSort.handle(SortEvent(table, FakeEventTarget))
    }

    @Test
    fun onScrollTo() {
        table.callOnScrollTo {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(ScrollToEvent.scrollToTopIndex(), it.eventType)
            assertEquals(0, it.scrollTarget)
        }
        table.onScrollTo.handle(ScrollToEvent(this, FakeEventTarget, ScrollToEvent.scrollToTopIndex(), 0))
    }

    @Test
    fun onScrollToColumn() {
        table.callOnScrollToColumn {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(ScrollToEvent.scrollToColumn<TreeTableColumn<Duration, Long>>(), it.eventType)
            assertEquals(column, it.scrollTarget)
        }
        table.onScrollToColumn.handle(ScrollToEvent(this, FakeEventTarget, ScrollToEvent.scrollToColumn(), column))
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/org/controlsfx/control/KtfxInfoOverlay.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import javafx.scene.Node
import ktfx.layouts.NodeManager
import org.controlsfx.control.InfoOverlay
import kotlin.contracts.ExperimentalContracts

/**
 * [InfoOverlay] with dynamic-layout dsl support.
 * Invoking dsl will only set its content.
 */
open class KtfxInfoOverlay(graphic: Node?, text: String?) : InfoOverlay(graphic, text), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { content = it }
}


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/layouts/LayoutsEntry.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.layouts

import com.hendraanggrian.kotlinpoet.classOf
import com.hendraanggrian.kotlinpoet.parameterizedBy
import com.hendraanggrian.ktfx.codegen.KTFX_LAYOUTS
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.ParameterSpec
import com.squareup.kotlinpoet.TypeName
import com.squareup.kotlinpoet.TypeVariableName
import com.squareup.kotlinpoet.asClassName
import javafx.scene.Node
import javafx.scene.control.Menu
import javafx.scene.control.MenuItem
import javafx.scene.control.Tab
import javafx.scene.control.TitledPane
import javafx.scene.control.ToggleButton
import javafx.scene.shape.PathElement
import kotlin.reflect.KClass
import kotlin.reflect.full.isSuperclassOf

data class LayoutsEntry(
    private val packageName: String,
    val kClass: KClass<*>,
    val parameters: List<ParameterSpec>,
    val typeVarNames: List<TypeVariableName>,
    private val customClass: Boolean
) {
    private companion object {
        val VALID_MANAGERS: Set<KClass<*>> = setOf(
            MenuItem::class,
            Menu::class,
            Node::class,
            PathElement::class,
            Tab::class,
            TitledPane::class,
            ToggleButton::class
        )
    }

    private val simpleName: String get() = kClass.simpleName!!

    val generatedName: String get() = "_$simpleName"

    val typeName: TypeName
        get() {
            val name = kClass.asClassName()
            return name.takeIf { typeVarNames.isEmpty() } ?: name.parameterizedBy(typeVarNames)
        }

    val customTypeName: TypeName
        get() = typeName.takeUnless { customClass } ?: packageName.classOf("Ktfx$simpleName")

    val managerClassNames: List<ClassName>
        get() = VALID_MANAGERS.filter { it == kClass || it.isSuperclassOf(kClass) }
            .map { KTFX_LAYOUTS.classOf("${it.simpleName}Manager") }

    val fullManagerClassNames: List<ClassName?>
        get() = listOf(null, *managerClassNames.toTypedArray())

    val functionName: String
        get() = simpleName.mapIndexed { index, c ->
            when {
                index == 0 || index == 1 -> c.lowercaseChar()
                c.isUpperCase() && simpleName.getOrNull(index + 1)?.isUpperCase() ?: false -> c.lowercaseChar()
                else -> c
            }
        }.joinToString("")

    val styledFunctionName: String get() = "styled$simpleName"

    val supportStyledFunction: Boolean get() = "ktfx.layouts".classOf("PathElementManager") !in managerClassNames

    fun getFileComment(add: Boolean, styled: Boolean, configured: Boolean): String = buildString {
        append(if (!add) "Create" else "Add")
        append(when {
            !styled && simpleName.first().let { it == 'A' || it == 'E' || it == 'I' || it == 'O' || it == 'U' } ->
                " an"
            else -> " a"
        })
        if (styled) append(" styled")
        append(" [$simpleName]")
        if (configured) append(" with configuration block")
        if (add) append(" to this manager")
        append('.')
    }

    fun getReturnsComment(add: Boolean, styled: Boolean): String = buildString {
        append("the")
        if (styled) append(" styled")
        append(" control")
        append(
            when {
                add -> " added"
                else -> " created"
            }
        )
        append('.')
    }
}


<|start_filename|>ktfx-commons/src/ktfx/controls/TableConstraints.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controls

import javafx.scene.control.TableView
import javafx.scene.control.TreeTableView

/** Apply [TableView.CONSTRAINED_RESIZE_POLICY] to this [TableView]. */
inline fun TableView<*>.constrained() {
    columnResizePolicy = TableView.CONSTRAINED_RESIZE_POLICY
}

/** Apply [TableView.UNCONSTRAINED_RESIZE_POLICY] to this [TableView]. */
inline fun TableView<*>.unconstrained() {
    columnResizePolicy = TableView.UNCONSTRAINED_RESIZE_POLICY
}

/** Apply [TreeTableView.CONSTRAINED_RESIZE_POLICY] to this [TreeTableView]. */
inline fun TreeTableView<*>.constrained() {
    columnResizePolicy = TreeTableView.CONSTRAINED_RESIZE_POLICY
}

/** Apply [TreeTableView.UNCONSTRAINED_RESIZE_POLICY] to this [TreeTableView]. */
inline fun TreeTableView<*>.unconstrained() {
    columnResizePolicy = TreeTableView.UNCONSTRAINED_RESIZE_POLICY
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXChipTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXChip
import com.jfoenix.controls.JFXChipView
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class JFXChipTest : LayoutsTest<KtfxPane, JFXChip<String>>() {
    private lateinit var jfxChipView: JFXChipView<String>

    override fun onCreate() {
        super.onCreate()
        jfxChipView = JFXChipView()
    }

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxChip(jfxChipView, "Yo") { }
    override fun KtfxPane.child2() = jfxChip(jfxChipView, "Yo")
    override fun KtfxPane.child3() = jfxChip(jfxChipView, "Yo") { }

    override fun JFXChip<String>.testDefaultValues() {
        assertEquals(jfxChipView, chipView)
        assertEquals("Yo", item)
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_PropertySheet.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import javafx.collections.ObservableList
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.PropertySheet
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [PropertySheet] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.propertySheet(items: ObservableList<PropertySheet.Item>? = null):
    PropertySheet = propertySheet(items = items) { }

/**
 * Create a [PropertySheet] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun propertySheet(
    items: ObservableList<PropertySheet.Item>? = null,
    configuration: (@KtfxLayoutDslMarker PropertySheet).() -> Unit
): PropertySheet {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PropertySheet(items)
    child.configuration()
    return child
}

/**
 * Add a [PropertySheet] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.propertySheet(
    items: ObservableList<PropertySheet.Item>? = null,
    configuration: (@KtfxLayoutDslMarker PropertySheet).() -> Unit
): PropertySheet {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PropertySheet(items)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [PropertySheet].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledPropertySheet(
    items: ObservableList<PropertySheet.Item>? = null,
    vararg styleClass: String,
    id: String? = null
): PropertySheet = styledPropertySheet(items = items, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [PropertySheet] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledPropertySheet(
    items: ObservableList<PropertySheet.Item>? = null,
    vararg styleClass: String,
    id: String? = null
): PropertySheet = styledPropertySheet(items = items, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [PropertySheet] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledPropertySheet(
    items: ObservableList<PropertySheet.Item>? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker PropertySheet).() -> Unit
): PropertySheet {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PropertySheet(items)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [PropertySheet] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledPropertySheet(
    items: ObservableList<PropertySheet.Item>? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker PropertySheet).() -> Unit
): PropertySheet {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PropertySheet(items)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_CheckComboBox.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import javafx.collections.FXCollections.observableArrayList
import javafx.collections.ObservableList
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.CheckComboBox
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [CheckComboBox] to this manager.
 *
 * @return the control added.
 */
public fun <T> NodeManager.checkComboBox(items: ObservableList<T> = observableArrayList()):
    CheckComboBox<T> = checkComboBox(items = items) { }

/**
 * Create a [CheckComboBox] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun <T> checkComboBox(
    items: ObservableList<T> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker CheckComboBox<T>).() -> Unit
): CheckComboBox<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CheckComboBox<T>(items)
    child.configuration()
    return child
}

/**
 * Add a [CheckComboBox] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun <T> NodeManager.checkComboBox(
    items: ObservableList<T> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker CheckComboBox<T>).() -> Unit
): CheckComboBox<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CheckComboBox<T>(items)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [CheckComboBox].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun <T> styledCheckComboBox(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): CheckComboBox<T> = styledCheckComboBox(items = items, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [CheckComboBox] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun <T> NodeManager.styledCheckComboBox(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): CheckComboBox<T> = styledCheckComboBox(items = items, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [CheckComboBox] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun <T> styledCheckComboBox(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker CheckComboBox<T>).() -> Unit
): CheckComboBox<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CheckComboBox<T>(items)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [CheckComboBox] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun <T> NodeManager.styledCheckComboBox(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker CheckComboBox<T>).() -> Unit
): CheckComboBox<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CheckComboBox<T>(items)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/HLineToTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.HLineTo
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class HLineToTest : LayoutsTest<KtfxPath, HLineTo>() {

    override fun manager() = KtfxPath()
    override fun KtfxPath.childCount() = elements.size
    override fun child1() = hlineTo { }
    override fun KtfxPath.child2() = hlineTo()
    override fun KtfxPath.child3() = hlineTo { }

    override fun HLineTo.testDefaultValues() {
        assertEquals(0.0, x)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ScrollBarTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.ScrollBar
import com.hendraanggrian.ktfx.test.LayoutsTest

class ScrollBarTest : LayoutsTest<KtfxPane, ScrollBar>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = scrollBar { }
    override fun KtfxPane.child2() = scrollBar()
    override fun KtfxPane.child3() = scrollBar { }
}

<|start_filename|>ktfx-commons/src/ktfx/cells/TableRows.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.cells

import javafx.scene.control.TableRow
import javafx.scene.control.TableView

/**
 * Sets a custom row factory to use in this [TableView].
 * @param S The type of the elements contained within the [TableView].
 * @param configuration custom initialization block that configures [KtfxTableRow].
 */
fun <S> TableView<S>.rowFactory(
    configuration: KtfxTableRow<S>.(TableView<S>) -> Unit
): Unit = setRowFactory { KtfxTableRow<S>().apply { configuration(it) } }

/** Custom [TableRow] configurator class. */
class KtfxTableRow<T> : TableRow<T>(), KtfxCell<T> {
    private var onEditStart: (() -> Unit)? = null
    private var onEditCommit: ((T?) -> Unit)? = null
    private var onEditCancel: (() -> Unit)? = null
    private var onUpdate: ((T?, empty: Boolean) -> Unit)? = null

    override fun onEditStart(action: () -> Unit) {
        onEditStart = action
    }

    override fun startEdit() {
        super.startEdit()
        onEditStart?.invoke()
    }

    override fun onEditCommit(action: (T?) -> Unit) {
        onEditCommit = action
    }

    override fun commitEdit(newValue: T?) {
        super.commitEdit(newValue)
        onEditCommit?.invoke(newValue)
    }

    override fun onEditCancel(action: () -> Unit) {
        onEditCancel = action
    }

    override fun cancelEdit() {
        super.cancelEdit()
        onEditCancel?.invoke()
    }

    override fun onUpdate(action: (T?, empty: Boolean) -> Unit) {
        onUpdate = action
    }

    override fun updateItem(item: T?, empty: Boolean) {
        super.updateItem(item, empty)
        onUpdate?.invoke(item, empty)
    }
}


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_Service.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.concurrent.Service
import javafx.concurrent.WorkerStateEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Service.setOnReady
 */
public fun Service<*>.onReady(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnReady { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Service.setOnScheduled
 */
public fun Service<*>.onScheduled(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnScheduled { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Service.setOnRunning
 */
public fun Service<*>.onRunning(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnRunning { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Service.setOnSucceeded
 */
public fun Service<*>.onSucceeded(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnSucceeded { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Service.setOnCancelled
 */
public fun Service<*>.onCancelled(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnCancelled { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Service.setOnFailed
 */
public fun Service<*>.onFailed(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnFailed { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-coroutines/src/javafx/scene/Node.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxCoroutinesKt")

package ktfx.coroutines

import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.scene.Node
import javafx.scene.SnapshotParameters
import javafx.scene.SnapshotResult
import javafx.scene.image.WritableImage
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext

/** Registers an event filter to this node. */
fun <E : Event> Node.eventFilter(
    context: CoroutineContext = Dispatchers.JavaFx,
    type: EventType<E>,
    action: suspend CoroutineScope.(E) -> Unit
): EventHandler<E> = EventHandler<E> { event -> GlobalScope.launch(context) { action(event) } }
    .also { addEventFilter(type, it) }

/** Registers an event handler to this node. */
fun <E : Event> Node.eventHandler(
    context: CoroutineContext = Dispatchers.JavaFx,
    type: EventType<E>,
    action: suspend CoroutineScope.(E) -> Unit
): EventHandler<E> = EventHandler<E> { event -> GlobalScope.launch(context) { action(event) } }
    .also { addEventHandler(type, it) }

/** Takes a snapshot of this node at the next frame and calls the specified callback method when the image is ready. */
fun Node.capture(
    context: CoroutineContext = Dispatchers.JavaFx,
    image: WritableImage? = null,
    configuration: SnapshotParameters.() -> Unit = { },
    callback: suspend (SnapshotResult) -> Unit
): Unit = snapshot(
    { param -> GlobalScope.launch(context) { callback(param) }; null },
    SnapshotParameters().apply(configuration),
    image
)


<|start_filename|>ktfx-commons/src/ktfx/controls/Animations.kt<|end_filename|>
package ktfx.controls

import javafx.animation.Animation
import javafx.animation.FadeTransition
import javafx.animation.FillTransition
import javafx.animation.ParallelTransition
import javafx.animation.PathTransition
import javafx.animation.RotateTransition
import javafx.animation.ScaleTransition
import javafx.animation.SequentialTransition
import javafx.animation.StrokeTransition
import javafx.animation.TranslateTransition
import javafx.scene.Node
import javafx.scene.paint.Color
import javafx.scene.shape.Shape
import javafx.util.Duration
import ktfx.time.milliseconds

/**
 * Plays a [FadeTransition].
 * @param duration length of this animation.
 * @param configuration the configuration block that customizes animation.
 * @return the animation played.
 */
fun Node.fadeTransition(
    duration: Duration = 400.0.milliseconds,
    configuration: FadeTransition.() -> Unit
): FadeTransition = FadeTransition(duration, this).apply {
    configuration()
    play()
}

/**
 * Plays a [FillTransition].
 * @param duration length of this animation.
 * @param configuration the configuration block that customizes animation.
 * @return the animation played.
 */
fun Shape.fillTransition(
    duration: Duration = 400.0.milliseconds,
    fromValue: Color? = null,
    toValue: Color? = null,
    configuration: FillTransition.() -> Unit
): FillTransition = FillTransition(duration, this, fromValue, toValue).apply {
    configuration()
    play()
}

/**
 * Plays a [PathTransition].
 * @param duration length of this animation.
 * @param configuration the configuration block that customizes animation.
 * @return the animation played.
 */
fun Node.pathTransition(
    duration: Duration = 400.0.milliseconds,
    path: Shape? = null,
    configuration: PathTransition.() -> Unit
): PathTransition = PathTransition(duration, path, this).apply {
    configuration()
    play()
}

/**
 * Plays a [RotateTransition].
 * @param duration length of this animation.
 * @param configuration the configuration block that customizes animation.
 * @return the animation played.
 */
fun Node.rotateTransition(
    duration: Duration = 400.0.milliseconds,
    configuration: RotateTransition.() -> Unit
): RotateTransition = RotateTransition(duration, this).apply {
    configuration()
    play()
}

/**
 * Plays a [ScaleTransition].
 * @param duration length of this animation.
 * @param configuration the configuration block that customizes animation.
 * @return the animation played.
 */
fun Node.scaleTransition(
    duration: Duration = 400.0.milliseconds,
    configuration: ScaleTransition.() -> Unit
): ScaleTransition = ScaleTransition(duration, this).apply {
    configuration()
    play()
}

/**
 * Plays a [StrokeTransition].
 * @param duration length of this animation.
 * @param configuration the configuration block that customizes animation.
 * @return the animation played.
 */
fun Shape.strokeTransition(
    duration: Duration = 400.0.milliseconds,
    fromValue: Color? = null,
    toValue: Color? = null,
    configuration: StrokeTransition.() -> Unit
): StrokeTransition = StrokeTransition(duration, this, fromValue, toValue).apply {
    configuration()
    play()
}

/**
 * Plays a [TranslateTransition].
 * @param duration length of this animation.
 * @param configuration the configuration block that customizes animation.
 * @return the animation played.
 */
fun Node.translateTransition(
    duration: Duration = 400.0.milliseconds,
    configuration: TranslateTransition.() -> Unit
): TranslateTransition = TranslateTransition(duration, this).apply {
    configuration()
    play()
}

/**
 * Creates a [ParallelTransition] for this node.
 * @param configuration the configuration block that customizes animations within this animation.
 * @return the animation played.
 */
fun Node.parallelTransition(
    configuration: AnimationScope.() -> Unit
): ParallelTransition = ParallelTransition(
    this,
    *object : AnimationScope {
        override val node: Node get() = this@parallelTransition
        override val animations: MutableCollection<Animation> = mutableListOf()
    }.apply(configuration).build()
)

/**
 * Creates a [ParallelTransition] for this shape.
 * @param configuration the configuration block that customizes animations within this animation.
 * @return the animation played.
 */
fun Shape.shapeParallelTransition(
    configuration: ShapeAnimationScope.() -> Unit
): ParallelTransition = ParallelTransition(
    this,
    *object : ShapeAnimationScope {
        override val node: Shape get() = this@shapeParallelTransition
        override val animations: MutableCollection<Animation> = mutableListOf()
    }.apply(configuration).build()
)

/**
 * Creates a [SequentialTransition] for this node.
 * @param configuration the configuration block that customizes animations within this animation.
 * @return the animation played.
 */
fun Node.sequentialTransition(
    configuration: AnimationScope.() -> Unit
): SequentialTransition = SequentialTransition(
    this,
    *object : AnimationScope {
        override val node: Node get() = this@sequentialTransition
        override val animations: MutableCollection<Animation> = mutableListOf()
    }.apply(configuration).build()
)

/**
 * Creates a [SequentialTransition] for this shape.
 * @param configuration the configuration block that customizes animations within this animation.
 * @return the animation played.
 */
fun Shape.shapeSequentialTransition(
    configuration: ShapeAnimationScope.() -> Unit
): SequentialTransition = SequentialTransition(
    this,
    *object : ShapeAnimationScope {
        override val node: Shape get() = this@shapeSequentialTransition
        override val animations: MutableCollection<Animation> = mutableListOf()
    }.apply(configuration).build()
)

/** Shape animations configurator interface for [ParallelTransition] and [SequentialTransition]. */
interface ShapeAnimationScope : AnimationScope {

    override val node: Shape

    /**
     * Append a [FillTransition].
     * @param duration length of this animation.
     * @param configuration the configuration block that customizes animation.
     * @return the animation added.
     */
    fun fill(
        duration: Duration = 400.0.milliseconds,
        fromValue: Color? = null,
        toValue: Color? = null,
        configuration: FillTransition.() -> Unit
    ): FillTransition = FillTransition(duration, node, fromValue, toValue).also {
        it.configuration()
        animations += it
    }

    /**
     * Append a [StrokeTransition].
     * @param duration length of this animation.
     * @param configuration the configuration block that customizes animation.
     * @return the animation added.
     */
    fun stroke(
        duration: Duration = 400.0.milliseconds,
        fromValue: Color? = null,
        toValue: Color? = null,
        configuration: StrokeTransition.() -> Unit
    ): StrokeTransition = StrokeTransition(duration, node, fromValue, toValue).also {
        it.configuration()
        animations += it
    }
}

/** Node animations configurator interface for [ParallelTransition] and [SequentialTransition]. */
interface AnimationScope {

    /** Node that the animations belong to. */
    val node: Node

    /** Collection of animations within this scope. */
    val animations: MutableCollection<Animation>

    /**
     * Append a [FadeTransition].
     * @param duration length of this animation.
     * @param configuration the configuration block that customizes animation.
     * @return the animation added.
     */
    fun fade(
        duration: Duration = 400.0.milliseconds,
        configuration: FadeTransition.() -> Unit
    ): FadeTransition = FadeTransition(duration, node).also {
        it.configuration()
        animations += it
    }

    /**
     * Append a [PathTransition].
     * @param duration length of this animation.
     * @param configuration the configuration block that customizes animation.
     * @return the animation added.
     */
    fun path(
        duration: Duration = 400.0.milliseconds,
        path: Shape? = null,
        configuration: PathTransition.() -> Unit
    ): PathTransition = PathTransition(duration, path, node).also {
        it.configuration()
        animations += it
    }

    /**
     * Append a [RotateTransition].
     * @param duration length of this animation.
     * @param configuration the configuration block that customizes animation.
     * @return the animation added.
     */
    fun rotate(
        duration: Duration = 400.0.milliseconds,
        configuration: RotateTransition.() -> Unit
    ): RotateTransition = RotateTransition(duration, node).also {
        it.configuration()
        animations += it
    }

    /**
     * Append a [ScaleTransition].
     * @param duration length of this animation.
     * @param configuration the configuration block that customizes animation.
     * @return the animation added.
     */
    fun scale(
        duration: Duration = 400.0.milliseconds,
        configuration: ScaleTransition.() -> Unit
    ): ScaleTransition = ScaleTransition(duration, node).also {
        it.configuration()
        animations += it
    }

    /**
     * Append a [TranslateTransition].
     * @param duration length of this animation.
     * @param configuration the configuration block that customizes animation.
     * @return the animation added.
     */
    fun translate(
        duration: Duration = 400.0.milliseconds,
        configuration: TranslateTransition.() -> Unit
    ): TranslateTransition = TranslateTransition(duration, node).also {
        it.configuration()
        animations += it
    }

    /** Return array of animations based on current configuration. */
    fun build(): Array<Animation> = animations.toTypedArray()
}


<|start_filename|>ktfx-commons/src/ktfx/collections/ObservableArraysFloat.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ObservableArraysKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.collections

import javafx.collections.FXCollections
import javafx.collections.ObservableFloatArray

/**
 * Creates a new empty observable [Float] array.
 * @see emptyArray
 */
inline fun emptyObservableFloatArray(): ObservableFloatArray = FXCollections.observableFloatArray()

/**
 * Creates a new empty observable [Float] array.
 * @see floatArrayOf
 */
inline fun observableFloatArrayOf(): ObservableFloatArray = FXCollections.observableFloatArray()

/**
 * Returns an observable array containing the specified [Float] numbers.
 * @see floatArrayOf
 */
fun observableFloatArrayOf(vararg elements: Float): ObservableFloatArray = when {
    elements.isNotEmpty() -> FXCollections.observableFloatArray(*elements)
    else -> FXCollections.observableFloatArray()
}

/**
 * Returns an observable array containing all of the [Float] numbers of this primitive array.
 * @see FloatArray.toTypedArray
 */
inline fun FloatArray.toObservableArray(): ObservableFloatArray = FXCollections.observableFloatArray(*this)

/** Returns an array containing copy of the observable array. */
fun ObservableFloatArray.toFloatArray(): FloatArray = toArray(FloatArray(size()))

/**
 * Returns new observable array which is a copy of the original array.
 * @see FloatArray.copyOf
 */
inline fun ObservableFloatArray.copyOf(): ObservableFloatArray = FXCollections.observableFloatArray(this)

/**
 * Returns `true` if [element] is found in the array.
 * @see FloatArray.contains
 */
operator fun ObservableFloatArray.contains(element: Float): Boolean = indexOf(element) >= 0

/**
 * Returns first index of [element], or -1 if the array does not contain element.
 * @see FloatArray.indexOf
 */
fun ObservableFloatArray.indexOf(element: Float): Int {
    for (index in indices) {
        if (element == this[index]) {
            return index
        }
    }
    return -1
}

/**
 * Returns last index of [element], or -1 if the array does not contain element.
 * @see FloatArray.lastIndexOf
 */
fun ObservableFloatArray.lastIndexOf(element: Float): Int {
    for (index in indices.reversed()) {
        if (element == this[index]) {
            return index
        }
    }
    return -1
}

/**
 * Returns an element at the given [index] or the result of calling the [defaultValue] function if the [index] is out of bounds of this array.
 * @see FloatArray.getOrElse
 */
inline fun ObservableFloatArray.getOrElse(index: Int, defaultValue: (Int) -> Float): Float =
    if (index in 0..lastIndex) get(index) else defaultValue(index)

/**
 * Returns an element at the given [index] or `null` if the [index] is out of bounds of this array.
 * @see FloatArray.getOrNull
 */
fun ObservableFloatArray.getOrNull(index: Int): Float? =
    if (index in 0..lastIndex) get(index) else null

/** Adds the specified [element] to this observable array. */
inline operator fun ObservableFloatArray.plusAssign(element: Float): Unit = addAll(element)

/** Adds all elements of the given [elements] array to this observable array. */
inline operator fun ObservableFloatArray.plusAssign(elements: FloatArray): Unit = addAll(*elements)

/** Adds all elements of the given [elements] observable array to this observable array. */
inline operator fun ObservableFloatArray.plusAssign(elements: ObservableFloatArray): Unit = addAll(elements)

/**
 * Performs the given [action] on each element.
 * @see FloatArray.forEach
 */
inline fun ObservableFloatArray.forEach(action: (Float) -> Unit) {
    for (index in 0 until size()) {
        action(this[index])
    }
}

/**
 * Performs the given [action] on each element, providing sequential index with the element.
 * @see FloatArray.forEachIndexed
 */
inline fun ObservableFloatArray.forEachIndexed(action: (index: Int, Float) -> Unit) {
    for (index in 0 until size()) {
        action(index, this[index])
    }
}

/**
 * Creates an iterator over the elements of the array.
 * @see FloatArray.iterator
 */
operator fun ObservableFloatArray.iterator(): FloatIterator = object : FloatIterator() {
    var index = 0
    override fun hasNext() = index < size()
    override fun nextFloat() = get(index++)
}


<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXProgressBar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXProgressBar
import javafx.scene.control.ProgressBar.INDETERMINATE_PROGRESS
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import kotlin.Double
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXProgressBar] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.jfxProgressBar(progress: Double = INDETERMINATE_PROGRESS): JFXProgressBar =
    jfxProgressBar(progress = progress) { }

/**
 * Create a [JFXProgressBar] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun jfxProgressBar(
    progress: Double = INDETERMINATE_PROGRESS,
    configuration: (@KtfxLayoutDslMarker JFXProgressBar).() -> Unit
): JFXProgressBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXProgressBar(progress)
    child.configuration()
    return child
}

/**
 * Add a [JFXProgressBar] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.jfxProgressBar(
    progress: Double = INDETERMINATE_PROGRESS,
    configuration: (@KtfxLayoutDslMarker JFXProgressBar).() -> Unit
): JFXProgressBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXProgressBar(progress)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXProgressBar].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledJFXProgressBar(
    progress: Double = INDETERMINATE_PROGRESS,
    vararg styleClass: String,
    id: String? = null
): JFXProgressBar = styledJFXProgressBar(progress = progress, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXProgressBar] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledJFXProgressBar(
    progress: Double = INDETERMINATE_PROGRESS,
    vararg styleClass: String,
    id: String? = null
): JFXProgressBar = styledJFXProgressBar(progress = progress, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [JFXProgressBar] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledJFXProgressBar(
    progress: Double = INDETERMINATE_PROGRESS,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXProgressBar).() -> Unit
): JFXProgressBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXProgressBar(progress)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXProgressBar] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledJFXProgressBar(
    progress: Double = INDETERMINATE_PROGRESS,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXProgressBar).() -> Unit
): JFXProgressBar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXProgressBar(progress)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/MenuTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.event.Event
import javafx.scene.control.Menu
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseMenuTest

class MenuTest : BaseMenuTest() {

    override fun Menu.callOnShowing(action: (Event) -> Unit) =
        onShowing(Dispatchers.Unconfined) { action(it) }

    override fun Menu.callOnShown(action: (Event) -> Unit) =
        onShown(Dispatchers.Unconfined) { action(it) }

    override fun Menu.callOnHiding(action: (Event) -> Unit) =
        onHiding(Dispatchers.Unconfined) { action(it) }

    override fun Menu.callOnHidden(action: (Event) -> Unit) =
        onHidden(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_MediaPlayer.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.media.MediaMarkerEvent
import javafx.scene.media.MediaPlayer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see MediaPlayer.setOnError
 */
public fun MediaPlayer.onError(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.() -> Unit
) {
    return setOnError { GlobalScope.launch(context) { action() } }
}

/**
 * @see MediaPlayer.setOnMarker
 */
public fun MediaPlayer.onMarker(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MediaMarkerEvent) -> Unit
) {
    return setOnMarker { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see MediaPlayer.setOnEndOfMedia
 */
public fun MediaPlayer.onEndOfMedia(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.() -> Unit
) {
    return setOnEndOfMedia { GlobalScope.launch(context) { action() } }
}

/**
 * @see MediaPlayer.setOnReady
 */
public fun MediaPlayer.onReady(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.() -> Unit
) {
    return setOnReady { GlobalScope.launch(context) { action() } }
}

/**
 * @see MediaPlayer.setOnPlaying
 */
public fun MediaPlayer.onPlaying(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.() -> Unit
) {
    return setOnPlaying { GlobalScope.launch(context) { action() } }
}

/**
 * @see MediaPlayer.setOnPaused
 */
public fun MediaPlayer.onPaused(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.() -> Unit
) {
    return setOnPaused { GlobalScope.launch(context) { action() } }
}

/**
 * @see MediaPlayer.setOnStopped
 */
public fun MediaPlayer.onStopped(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.() -> Unit
) {
    return setOnStopped { GlobalScope.launch(context) { action() } }
}

/**
 * @see MediaPlayer.setOnHalted
 */
public fun MediaPlayer.onHalted(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.() -> Unit
) {
    return setOnHalted { GlobalScope.launch(context) { action() } }
}

/**
 * @see MediaPlayer.setOnRepeat
 */
public fun MediaPlayer.onRepeat(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.() -> Unit
) {
    return setOnRepeat { GlobalScope.launch(context) { action() } }
}

/**
 * @see MediaPlayer.setOnStalled
 */
public fun MediaPlayer.onStalled(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.() -> Unit
) {
    return setOnStalled { GlobalScope.launch(context) { action() } }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/SphereTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.Sphere
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class SphereTest : LayoutsTest<KtfxPane, Sphere>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = sphere { }
    override fun KtfxPane.child2() = sphere()
    override fun KtfxPane.child3() = sphere { }

    override fun Sphere.testDefaultValues() {
        assertEquals(1.0, radius)
        assertEquals(64, divisions)
    }
}

<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseListViewTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.control.ListView
import javafx.scene.control.ScrollToEvent
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseListViewTest {
    private lateinit var list: ListView<String>

    abstract fun <E> ListView<E>.callOnEditStart(action: (ListView.EditEvent<E>) -> Unit)
    abstract fun <E> ListView<E>.callOnEditCommit(action: (ListView.EditEvent<E>) -> Unit)
    abstract fun <E> ListView<E>.callOnEditCancel(action: (ListView.EditEvent<E>) -> Unit)
    abstract fun <E> ListView<E>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        list = ListView()
    }

    @Test
    fun onEditStart() {
        list.callOnEditStart {
            assertEquals(list, it.source)
            assertEquals(ListView.editStartEvent<String>(), it.eventType)
            assertEquals("", it.newValue)
            assertEquals(0, it.index)
        }
        list.onEditStart.handle(ListView.EditEvent(list, ListView.editStartEvent(), "", 0))
    }

    @Test
    fun onEditCommit() {
        list.callOnEditCommit {
            assertEquals(list, it.source)
            assertEquals(ListView.editCommitEvent<String>(), it.eventType)
            assertEquals("", it.newValue)
            assertEquals(0, it.index)
        }
        list.onEditCommit.handle(ListView.EditEvent(list, ListView.editCommitEvent(), "", 0))
    }

    @Test
    fun onEditCancel() {
        list.callOnEditCancel {
            assertEquals(list, it.source)
            assertEquals(ListView.editCancelEvent<String>(), it.eventType)
            assertEquals("", it.newValue)
            assertEquals(0, it.index)
        }
        list.onEditCancel.handle(ListView.EditEvent(list, ListView.editCancelEvent(), "", 0))
    }

    @Test
    fun onScrollTo() {
        list.callOnScrollTo {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(ScrollToEvent.scrollToTopIndex(), it.eventType)
            assertEquals(0, it.scrollTarget)
        }
        list.onScrollTo.handle(ScrollToEvent(this, FakeEventTarget, ScrollToEvent.scrollToTopIndex(), 0))
    }
}

<|start_filename|>thirdparty/jfoenix-commons/src/ktfx/jfoenix/dialogs/JFXAlerts.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.jfoenix.dialogs

import com.jfoenix.controls.JFXAlert
import javafx.scene.Node
import javafx.scene.image.ImageView
import javafx.stage.Stage
import ktfx.dialogs.graphicIcon
import ktfx.dialogs.headerTitle
import java.util.Optional

/**
 * Show a JFoenix alert with title and graphic.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param dialogAction custom dialog action.
 * @return dialog result.
 */
fun <R> Stage.jfxAlert(
    title: String? = null,
    graphic: Node? = null,
    dialogAction: (JFXAlert<R>.() -> Unit)? = null
): Optional<R> = JFXAlert<R>(this).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    dialogAction?.invoke(dialog)
}.showAndWait()

/**
 * Show an JFoenix alert.
 * @param dialogAction custom dialog action.
 * @return dialog result.
 */
inline fun <R> Stage.jfxAlert(
    noinline dialogAction: (JFXAlert<R>.() -> Unit)? = null
): Optional<R> = jfxAlert(null, null, dialogAction)


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/CubicCurveTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.CubicCurve
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class CubicCurveTest : LayoutsTest<KtfxPane, CubicCurve>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = cubicCurve { }
    override fun KtfxPane.child2() = cubicCurve()
    override fun KtfxPane.child3() = cubicCurve { }

    override fun CubicCurve.testDefaultValues() {
        assertEquals(0.0, startX)
        assertEquals(0.0, startY)
        assertEquals(0.0, controlX1)
        assertEquals(0.0, controlX2)
        assertEquals(0.0, controlY1)
        assertEquals(0.0, controlY2)
        assertEquals(0.0, endX)
        assertEquals(0.0, endY)
    }
}

<|start_filename|>ktfx-listeners/src/javafx/beans/Observable.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.beans.InvalidationListener
import javafx.beans.Observable

/** Adds an [InvalidationListener] which will be notified whenever the [Observable] becomes invalid. */
inline fun Observable.listener(
    noinline listener: (Observable) -> Unit
): InvalidationListener = InvalidationListener(listener).also { addListener(it) }


<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXToolbar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXToolbar
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXToolbar] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.jfxToolbar(): JFXToolbar = jfxToolbar() { }

/**
 * Create a [JFXToolbar] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun jfxToolbar(configuration: (@KtfxLayoutDslMarker KtfxJFXToolbar).() -> Unit):
    JFXToolbar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXToolbar()
    child.configuration()
    return child
}

/**
 * Add a [JFXToolbar] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.jfxToolbar(
    configuration: (@KtfxLayoutDslMarker KtfxJFXToolbar).() ->
    Unit
): JFXToolbar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXToolbar()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXToolbar].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledJFXToolbar(vararg styleClass: String, id: String? = null): JFXToolbar =
    styledJFXToolbar(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXToolbar] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledJFXToolbar(vararg styleClass: String, id: String? = null): JFXToolbar =
    styledJFXToolbar(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [JFXToolbar] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledJFXToolbar(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxJFXToolbar).() -> Unit
): JFXToolbar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXToolbar()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXToolbar] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledJFXToolbar(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxJFXToolbar).() -> Unit
): JFXToolbar {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXToolbar()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/AccordionTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.control.Accordion
import javafx.scene.control.Label
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class AccordionTest : LayoutsTest<KtfxPane, Accordion>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = accordion { }
    override fun KtfxPane.child2() = accordion()
    override fun KtfxPane.child3() = accordion { }

    @Test
    fun stringInvocation() {
        accordion {
            assertThat(panes).isEmpty()
            titledPane("Hello")
            "World" {
                label("haha")
            }
            assertEquals(2, panes.size)
            assertTrue(panes[1].content is Label)
        }
    }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/stage/WindowTest.kt<|end_filename|>
package ktfx.listeners

import javafx.stage.BaseWindowTest
import javafx.stage.Window
import javafx.stage.WindowEvent

class WindowTest : BaseWindowTest() {

    override fun Window.callOnCloseRequest(action: (WindowEvent) -> Unit) = onCloseRequest(action)
    override fun Window.callOnShowing(action: (WindowEvent) -> Unit) = onShowing(action)
    override fun Window.callOnShown(action: (WindowEvent) -> Unit) = onShown(action)
    override fun Window.callOnHiding(action: (WindowEvent) -> Unit) = onHiding(action)
    override fun Window.callOnHidden(action: (WindowEvent) -> Unit) = onHidden(action)
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_LineTo.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.LineTo
import kotlin.Double
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [LineTo] to this manager.
 *
 * @return the control added.
 */
public fun PathElementManager.lineTo(x: Double = 0.0, y: Double = 0.0): LineTo = lineTo(
    x = x,
    y =
    y
) { }

/**
 * Create a [LineTo] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun lineTo(
    x: Double = 0.0,
    y: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker LineTo).() -> Unit
): LineTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = LineTo(x, y)
    child.configuration()
    return child
}

/**
 * Add a [LineTo] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun PathElementManager.lineTo(
    x: Double = 0.0,
    y: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker LineTo).() -> Unit
): LineTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = LineTo(x, y)
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/src/KtfxLayoutDslMarker.kt<|end_filename|>
package ktfx.layouts

/** Delimits dynamic-layouts DSL. */
@DslMarker
@Target(AnnotationTarget.TYPE)
annotation class KtfxLayoutDslMarker


<|start_filename|>ktfx-layouts/src/javafx/scene/layout/KtfxAnchorPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.layout.AnchorPane
import kotlin.contracts.ExperimentalContracts

/**
 * [AnchorPane] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxAnchorPane : AnchorPane(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { children += it }

    /** Top anchor of this children. */
    inline var Node.topAnchor: Double?
        @JvmName("getTopAnchor2") get() = getTopAnchor(this)
        @JvmName("setTopAnchor2") set(value) = setTopAnchor(this, value)

    /** Right anchor of this children. */
    inline var Node.rightAnchor: Double?
        @JvmName("getRightAnchor2") get() = getRightAnchor(this)
        @JvmName("setRightAnchor2") set(value) = setRightAnchor(this, value)

    /** Bottom anchor of this children. */
    inline var Node.bottomAnchor: Double?
        @JvmName("getBottomAnchor2") get() = getBottomAnchor(this)
        @JvmName("setBottomAnchor2") set(value) = setBottomAnchor(this, value)

    /** Left anchor of this children. */
    inline var Node.leftAnchor: Double?
        @JvmName("getLeftAnchor2") get() = getLeftAnchor(this)
        @JvmName("setLeftAnchor2") set(value) = setLeftAnchor(this, value)

    /** Set children anchor on all side in this layout. */
    fun <C : Node> C.anchor(all: Int): C = anchor(all, all, all, all)

    /** Set children anchor on each side in this layout. */
    fun <C : Node> C.anchor(horizontal: Int = Int.MAX_VALUE, vertical: Int = Int.MAX_VALUE): C =
        anchor(vertical, horizontal, vertical, horizontal)

    /** Set children anchor on each side in this layout. */
    fun <C : Node> C.anchor(
        top: Int = Int.MAX_VALUE,
        right: Int = Int.MAX_VALUE,
        bottom: Int = Int.MAX_VALUE,
        left: Int = Int.MAX_VALUE
    ): C = anchor(
        if (top != Int.MAX_VALUE) top.toDouble() else Double.NaN,
        if (right != Int.MAX_VALUE) right.toDouble() else Double.NaN,
        if (bottom != Int.MAX_VALUE) bottom.toDouble() else Double.NaN,
        if (left != Int.MAX_VALUE) left.toDouble() else Double.NaN
    )

    /** Set children anchor on all side in this layout. */
    fun <C : Node> C.anchor(all: Long): C = anchor(all, all, all, all)

    /** Set children anchor on each side in this layout. */
    fun <C : Node> C.anchor(horizontal: Long = Long.MAX_VALUE, vertical: Long = Long.MAX_VALUE): C =
        anchor(vertical, horizontal, vertical, horizontal)

    /** Set children anchor on each side in this layout. */
    fun <C : Node> C.anchor(
        top: Long = Long.MAX_VALUE,
        right: Long = Long.MAX_VALUE,
        bottom: Long = Long.MAX_VALUE,
        left: Long = Long.MAX_VALUE
    ): C = anchor(
        if (top != Long.MAX_VALUE) top.toDouble() else Double.NaN,
        if (right != Long.MAX_VALUE) right.toDouble() else Double.NaN,
        if (bottom != Long.MAX_VALUE) bottom.toDouble() else Double.NaN,
        if (left != Long.MAX_VALUE) left.toDouble() else Double.NaN
    )

    /** Set children anchor on all side in this layout. */
    fun <C : Node> C.anchor(all: Double): C = anchor(all, all, all, all)

    /** Set children anchor on each side in this layout. */
    fun <C : Node> C.anchor(horizontal: Double = Double.NaN, vertical: Double = Double.NaN): C =
        anchor(vertical, horizontal, vertical, horizontal)

    /** Set children anchor on each side in this layout. */
    @Suppress("ConvertNaNEquality")
    fun <C : Node> C.anchor(
        top: Double = Double.NaN,
        right: Double = Double.NaN,
        bottom: Double = Double.NaN,
        left: Double = Double.NaN
    ): C {
        if (topAnchor != Double.NaN) topAnchor = top
        if (rightAnchor != Double.NaN) rightAnchor = right
        if (bottomAnchor != Double.NaN) bottomAnchor = bottom
        if (leftAnchor != Double.NaN) leftAnchor = left
        return this
    }

    /** Clear children constraints. */
    @JvmName("clearConstraints2")
    inline fun Node.clearConstraints(): Unit = clearConstraints(this)
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/collections/ObservableListTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.collections.ListChangeListener
import javafx.collections.ObservableList
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseObservableListTest

class ObservableListTest : BaseObservableListTest() {

    override fun <E> ObservableList<E>.callListener(action: (ListChangeListener.Change<out E>) -> Unit) {
        listener<E>(Dispatchers.Unconfined) { action(it) }
    }
}

<|start_filename|>ktfx-commons/src/ktfx/inputs/MouseEvent.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.inputs

import javafx.scene.input.MouseButton
import javafx.scene.input.MouseEvent

/** Convenient method to check if mouse event is left click. */
inline fun MouseEvent.isLeftClick(): Boolean = button == MouseButton.PRIMARY && clickCount == 1

/** Convenient method to check if mouse event is right click. */
inline fun MouseEvent.isRightClick(): Boolean = button == MouseButton.SECONDARY && clickCount == 1

/** Convenient method to check if mouse event is middle click. */
inline fun MouseEvent.isMiddleClick(): Boolean = button == MouseButton.MIDDLE && clickCount == 1

/** Convenient method to check if mouse event is double click. */
inline fun MouseEvent.isDoubleClick(): Boolean = button == MouseButton.PRIMARY && clickCount == 2


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/listeners/ListenersFactories.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.listeners

import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.ParameterSpec
import com.squareup.kotlinpoet.TypeName
import com.squareup.kotlinpoet.asTypeName
import com.hendraanggrian.kotlinpoet.FileSpecBuilder
import com.hendraanggrian.kotlinpoet.buildParameterSpec
import com.hendraanggrian.kotlinpoet.dsl.ParameterSpecHandlerScope
import com.hendraanggrian.kotlinpoet.lambdaBy
import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext
import kotlin.reflect.KClass

open class ListenersFactory(
    path: String,
    packageName: String,
    className: String
) : BaseListenersFactory(
    path,
    packageName,
    className,
    KModifier.INLINE,
    extraFileConfiguration = {
        annotations.add<Suppress> { addMember("%S", "NOTHING_TO_INLINE") }
    }
) {
    companion object;

    override fun ParameterSpecHandlerScope.action(vararg params: TypeName): Boolean =
        add("action", Unit::class.asTypeName().lambdaBy(*params), KModifier.NOINLINE)
}

open class CoroutinesFactory(
    path: String,
    packageName: String,
    className: String
) : BaseListenersFactory(
    path,
    packageName,
    className,
    null,
    buildParameterSpec<CoroutineContext>("context") { defaultValue("Dispatchers.JavaFx") },
    {
        addImport("kotlinx.coroutines", "GlobalScope")
        addImport("kotlinx.coroutines", "Dispatchers")
        addImport("kotlinx.coroutines", "launch")
        addImport("kotlinx.coroutines.javafx", "JavaFx")
    }
) {
    companion object;

    override fun ParameterSpecHandlerScope.action(vararg params: TypeName): Boolean = add(
        "action", Unit::class.asTypeName().lambdaBy(*params, receiver = CoroutineScope::class.asTypeName())
            .copy(suspending = true)
    )
}

abstract class BaseListenersFactory(
    val path: String,
    val packageName: String,
    val className: String,
    val extraFunctionModifier: KModifier? = null,
    private val extraFunctionParameter: ParameterSpec? = null,
    val extraFileConfiguration: FileSpecBuilder.() -> Unit = { }
) {
    val entries = mutableListOf<ListenersClassEntry>()

    operator fun KClass<*>.invoke(configuration: FunctionsFactory.() -> Unit) = asTypeName().invoke(configuration)

    operator fun TypeName.invoke(configuration: FunctionsFactory.() -> Unit) {
        entries += ListenersClassEntry(
            this,
            extraFunctionModifier,
            FunctionsFactory(extraFunctionParameter).apply(configuration).entries,
            extraFileConfiguration
        )
    }

    inline fun <reified Type> ParameterSpecHandlerScope.action(): Boolean = action(Type::class.asTypeName())

    abstract fun ParameterSpecHandlerScope.action(vararg params: TypeName): Boolean

    class FunctionsFactory(private val extraFunctionParameter: ParameterSpec?) {
        val entries = mutableListOf<ListenersFunctionEntry>()

        operator fun String.invoke(configuration: ParameterSpecHandlerScope.() -> Unit = { }) {
            val parameters = listOfNotNull(extraFunctionParameter).toMutableList()
            ParameterSpecHandlerScope(parameters).configuration()
            entries += ListenersFunctionEntry(this, parameters)
        }
    }
}

<|start_filename|>testing/listeners-coroutines-controlsfx/src/org/controlsfx/control/BasePlusMinusSliderTest.kt<|end_filename|>
package ktfx.controlsfx.test

import com.hendraanggrian.ktfx.test.FakeEventTarget
import com.hendraanggrian.ktfx.test.initToolkit
import org.controlsfx.control.PlusMinusSlider
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BasePlusMinusSliderTest {
    private lateinit var slider: PlusMinusSlider

    abstract fun PlusMinusSlider.callOnValueChanged(action: (PlusMinusSlider.PlusMinusEvent) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        slider = PlusMinusSlider()
    }

    @Test
    fun onValueChanged() {
        slider.callOnValueChanged {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(PlusMinusSlider.PlusMinusEvent.VALUE_CHANGED, it.eventType)
            assertEquals(0.0, it.value)
        }
        slider.onValueChanged.handle(
            PlusMinusSlider.PlusMinusEvent(this, FakeEventTarget, PlusMinusSlider.PlusMinusEvent.VALUE_CHANGED, 0.0)
        )
    }
}


<|start_filename|>testing/listeners-coroutines/src/com/hendraanggrian/ktfx/test/events/FakeRotateEvent.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.EventType
import javafx.scene.input.RotateEvent
import kotlin.test.assertEquals
import kotlin.test.assertFalse

/**
 * @receiver source of this fake event.
 */
fun Any.assertFakeRotateEvent(actual: RotateEvent, expectedType: EventType<RotateEvent>) {
    assertEquals(this, actual.source)
    assertEquals(FakeEventTarget, actual.target)
    assertEquals(expectedType, actual.eventType)
    assertEquals(0.0, actual.x)
    assertEquals(0.0, actual.y)
    assertEquals(0.0, actual.screenX)
    assertEquals(0.0, actual.screenY)
    assertFalse(actual.isShiftDown)
    assertFalse(actual.isControlDown)
    assertFalse(actual.isAltDown)
    assertFalse(actual.isMetaDown)
    assertFalse(actual.isDirect)
    assertFalse(actual.isInertia)
    assertEquals(0.0, actual.angle)
    assertEquals(0.0, actual.totalAngle)
    assertEquals(FakePickResult, actual.pickResult)
}

/**
 * @receiver source of this fake event.
 */
fun Any.fakeRotateEventOf(eventType: EventType<RotateEvent>) = RotateEvent(
    this, FakeEventTarget, eventType,
    0.0, 0.0,
    0.0, 0.0,
    false,
    false,
    false,
    false,
    false,
    false, 0.0, 0.0, FakePickResult
)

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/TitledPaneTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.TitledPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class TitledPaneTest : LayoutsTest<KtfxAccordion, TitledPane>() {

    override fun manager() = KtfxAccordion()
    override fun KtfxAccordion.childCount() = panes.size
    override fun child1() = titledPane { }
    override fun KtfxAccordion.child2() = titledPane()
    override fun KtfxAccordion.child3() = titledPane { }

    override fun TitledPane.testDefaultValues() {
        assertNull(text)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/NumberValueBinding.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("NumberValueBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.NumberBinding
import javafx.beans.binding.NumberExpressionBase
import javafx.beans.value.ObservableNumberValue

/** @see NumberExpressionBase.add */
inline operator fun ObservableNumberValue.plus(other: ObservableNumberValue): NumberBinding = Bindings.add(this, other)

/** @see NumberExpressionBase.subtract */
inline operator fun ObservableNumberValue.minus(other: ObservableNumberValue): NumberBinding =
    Bindings.subtract(this, other)

/** @see NumberExpressionBase.multiply */
inline operator fun ObservableNumberValue.times(other: ObservableNumberValue): NumberBinding =
    Bindings.multiply(this, other)

/** @see NumberExpressionBase.divide */
inline operator fun ObservableNumberValue.div(other: ObservableNumberValue): NumberBinding =
    Bindings.divide(this, other)

/** @see NumberExpressionBase.isEqualTo */
inline infix fun ObservableNumberValue.eq(other: ObservableNumberValue): BooleanBinding = Bindings.equal(this, other)

/** @see NumberExpressionBase.isEqualTo */
inline fun ObservableNumberValue.eq(other: ObservableNumberValue, epsilon: Double): BooleanBinding =
    Bindings.equal(this, other, epsilon)

/** This function is weirdly not inherited by [NumberExpressionBase]. */
inline infix fun ObservableNumberValue.eq(other: Double): BooleanBinding = Bindings.equal(this, other, 0.0)

/** This function is weirdly not inherited by [NumberExpressionBase]. */
inline infix fun Double.eq(other: ObservableNumberValue): BooleanBinding = Bindings.equal(this, other, 0.0)

/** @see NumberExpressionBase.isEqualTo */
inline fun ObservableNumberValue.eq(other: Double, epsilon: Double): BooleanBinding =
    Bindings.equal(this, other, epsilon)

/** @see NumberExpressionBase.isEqualTo */
inline fun Double.eq(other: ObservableNumberValue, epsilon: Double): BooleanBinding =
    Bindings.equal(this, other, epsilon)

/** This function is weirdly not inherited by [NumberExpressionBase]. */
inline infix fun ObservableNumberValue.eq(other: Float): BooleanBinding = Bindings.equal(this, other, 0.0)

/** This function is weirdly not inherited by [NumberExpressionBase]. */
inline infix fun Float.eq(other: ObservableNumberValue): BooleanBinding = Bindings.equal(this, other, 0.0)

/** @see NumberExpressionBase.isEqualTo */
inline fun ObservableNumberValue.eq(other: Float, epsilon: Double): BooleanBinding =
    Bindings.equal(this, other, epsilon)

/** @see NumberExpressionBase.isEqualTo */
inline fun Float.eq(other: ObservableNumberValue, epsilon: Double): BooleanBinding =
    Bindings.equal(this, other, epsilon)

/** @see NumberExpressionBase.isEqualTo */
inline infix fun ObservableNumberValue.eq(other: Long): BooleanBinding = Bindings.equal(this, other)

/** @see NumberExpressionBase.isEqualTo */
inline infix fun Long.eq(other: ObservableNumberValue): BooleanBinding = Bindings.equal(this, other)

/** @see NumberExpressionBase.isEqualTo */
inline fun ObservableNumberValue.eq(other: Long, epsilon: Double): BooleanBinding =
    Bindings.equal(this, other, epsilon)

/** @see NumberExpressionBase.isEqualTo */
inline fun Long.eq(other: ObservableNumberValue, epsilon: Double): BooleanBinding =
    Bindings.equal(this, other, epsilon)

/** @see NumberExpressionBase.isEqualTo */
inline infix fun ObservableNumberValue.eq(other: Int): BooleanBinding = Bindings.equal(this, other)

/** @see NumberExpressionBase.isEqualTo */
inline infix fun Int.eq(other: ObservableNumberValue): BooleanBinding = Bindings.equal(this, other)

/** @see NumberExpressionBase.isEqualTo */
inline fun ObservableNumberValue.eq(other: Int, epsilon: Double): BooleanBinding =
    Bindings.equal(this, other, epsilon)

/** @see NumberExpressionBase.isEqualTo */
inline fun Int.eq(other: ObservableNumberValue, epsilon: Double): BooleanBinding =
    Bindings.equal(this, other, epsilon)

/** @see NumberExpressionBase.isNotEqualTo */
inline infix fun ObservableNumberValue.neq(other: ObservableNumberValue): BooleanBinding =
    Bindings.notEqual(this, other)

/** @see NumberExpressionBase.isNotEqualTo */
inline fun ObservableNumberValue.neq(other: ObservableNumberValue, epsilon: Double): BooleanBinding =
    Bindings.notEqual(this, other, epsilon)

/** This function is weirdly not inherited by [NumberExpressionBase]. */
inline infix fun ObservableNumberValue.neq(other: Double): BooleanBinding = Bindings.notEqual(this, other, 0.0)

/** This function is weirdly not inherited by [NumberExpressionBase]. */
inline infix fun Double.neq(other: ObservableNumberValue): BooleanBinding = Bindings.notEqual(this, other, 0.0)

/** @see NumberExpressionBase.isNotEqualTo */
inline fun ObservableNumberValue.neq(other: Double, epsilon: Double): BooleanBinding =
    Bindings.notEqual(this, other, epsilon)

/** @see NumberExpressionBase.isNotEqualTo */
inline fun Double.neq(other: ObservableNumberValue, epsilon: Double): BooleanBinding =
    Bindings.notEqual(this, other, epsilon)

/** This function is weirdly not inherited by [NumberExpressionBase]. */
inline infix fun ObservableNumberValue.neq(other: Float): BooleanBinding = Bindings.notEqual(this, other, 0.0)

/** This function is weirdly not inherited by [NumberExpressionBase]. */
inline infix fun Float.neq(other: ObservableNumberValue): BooleanBinding = Bindings.notEqual(this, other, 0.0)

/** @see NumberExpressionBase.isNotEqualTo */
inline fun ObservableNumberValue.neq(other: Float, epsilon: Double): BooleanBinding =
    Bindings.notEqual(this, other, epsilon)

/** @see NumberExpressionBase.isNotEqualTo */
inline fun Float.neq(other: ObservableNumberValue, epsilon: Double): BooleanBinding =
    Bindings.notEqual(this, other, epsilon)

/** @see NumberExpressionBase.isNotEqualTo */
inline infix fun ObservableNumberValue.neq(other: Long): BooleanBinding = Bindings.notEqual(this, other)

/** @see NumberExpressionBase.isNotEqualTo */
inline infix fun Long.neq(other: ObservableNumberValue): BooleanBinding = Bindings.notEqual(this, other)

/** @see NumberExpressionBase.isNotEqualTo */
inline fun ObservableNumberValue.neq(other: Long, epsilon: Double): BooleanBinding =
    Bindings.notEqual(this, other, epsilon)

/** @see NumberExpressionBase.isNotEqualTo */
inline fun Long.neq(other: ObservableNumberValue, epsilon: Double): BooleanBinding =
    Bindings.notEqual(this, other, epsilon)

/** @see NumberExpressionBase.isNotEqualTo */
inline infix fun ObservableNumberValue.neq(other: Int): BooleanBinding = Bindings.notEqual(this, other)

/** @see NumberExpressionBase.isNotEqualTo */
inline infix fun Int.neq(other: ObservableNumberValue): BooleanBinding = Bindings.notEqual(this, other)

/** @see NumberExpressionBase.isNotEqualTo */
inline fun ObservableNumberValue.neq(other: Int, epsilon: Double): BooleanBinding =
    Bindings.notEqual(this, other, epsilon)

/** @see NumberExpressionBase.isNotEqualTo */
inline fun Int.neq(other: ObservableNumberValue, epsilon: Double): BooleanBinding =
    Bindings.notEqual(this, other, epsilon)

/** @see NumberExpressionBase.greaterThan */
inline infix fun ObservableNumberValue.greater(other: ObservableNumberValue): BooleanBinding =
    Bindings.greaterThan(this, other)

/** @see NumberExpressionBase.greaterThan */
inline infix fun ObservableNumberValue.greater(other: Double): BooleanBinding =
    Bindings.greaterThan(this, other)

/** @see NumberExpressionBase.greaterThan */
inline infix fun Double.greater(other: ObservableNumberValue): BooleanBinding =
    Bindings.greaterThan(this, other)

/** @see NumberExpressionBase.greaterThan */
inline infix fun ObservableNumberValue.greater(other: Float): BooleanBinding =
    Bindings.greaterThan(this, other)

/** @see NumberExpressionBase.greaterThan */
inline infix fun Float.greater(other: ObservableNumberValue): BooleanBinding =
    Bindings.greaterThan(this, other)

/** @see NumberExpressionBase.greaterThan */
inline infix fun ObservableNumberValue.greater(other: Long): BooleanBinding =
    Bindings.greaterThan(this, other)

/** @see NumberExpressionBase.greaterThan */
inline infix fun Long.greater(other: ObservableNumberValue): BooleanBinding =
    Bindings.greaterThan(this, other)

/** @see NumberExpressionBase.greaterThan */
inline infix fun ObservableNumberValue.greater(other: Int): BooleanBinding =
    Bindings.greaterThan(this, other)

/** @see NumberExpressionBase.greaterThan */
inline infix fun Int.greater(other: ObservableNumberValue): BooleanBinding =
    Bindings.greaterThan(this, other)

/** @see NumberExpressionBase.lessThan */
inline infix fun ObservableNumberValue.less(other: ObservableNumberValue): BooleanBinding =
    Bindings.lessThan(this, other)

/** @see NumberExpressionBase.lessThan */
inline infix fun ObservableNumberValue.less(other: Double): BooleanBinding =
    Bindings.lessThan(this, other)

/** @see NumberExpressionBase.lessThan */
inline infix fun Double.less(other: ObservableNumberValue): BooleanBinding =
    Bindings.lessThan(this, other)

/** @see NumberExpressionBase.lessThan */
inline infix fun ObservableNumberValue.less(other: Float): BooleanBinding =
    Bindings.lessThan(this, other)

/** @see NumberExpressionBase.lessThan */
inline infix fun Float.less(other: ObservableNumberValue): BooleanBinding =
    Bindings.lessThan(this, other)

/** @see NumberExpressionBase.lessThan */
inline infix fun ObservableNumberValue.less(other: Long): BooleanBinding =
    Bindings.lessThan(this, other)

/** @see NumberExpressionBase.lessThan */
inline infix fun Long.less(other: ObservableNumberValue): BooleanBinding =
    Bindings.lessThan(this, other)

/** @see NumberExpressionBase.lessThan */
inline infix fun ObservableNumberValue.less(other: Int): BooleanBinding =
    Bindings.lessThan(this, other)

/** @see NumberExpressionBase.lessThan */
inline infix fun Int.less(other: ObservableNumberValue): BooleanBinding =
    Bindings.lessThan(this, other)

/** @see NumberExpressionBase.greaterThanOrEqualTo */
inline infix fun ObservableNumberValue.greaterEq(other: ObservableNumberValue): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see NumberExpressionBase.greaterThanOrEqualTo */
inline infix fun ObservableNumberValue.greaterEq(other: Double): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see NumberExpressionBase.greaterThanOrEqualTo */
inline infix fun Double.greaterEq(other: ObservableNumberValue): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see NumberExpressionBase.greaterThanOrEqualTo */
inline infix fun ObservableNumberValue.greaterEq(other: Float): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see NumberExpressionBase.greaterThanOrEqualTo */
inline infix fun Float.greaterEq(other: ObservableNumberValue): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see NumberExpressionBase.greaterThanOrEqualTo */
inline infix fun ObservableNumberValue.greaterEq(other: Long): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see NumberExpressionBase.greaterThanOrEqualTo */
inline infix fun Long.greaterEq(other: ObservableNumberValue): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see NumberExpressionBase.greaterThanOrEqualTo */
inline infix fun ObservableNumberValue.greaterEq(other: Int): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see NumberExpressionBase.greaterThanOrEqualTo */
inline infix fun Int.greaterEq(other: ObservableNumberValue): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see NumberExpressionBase.lessThanOrEqualTo */
inline infix fun ObservableNumberValue.lessEq(other: ObservableNumberValue): BooleanBinding =
    Bindings.lessThanOrEqual(this, other)

/** @see NumberExpressionBase.lessThanOrEqualTo */
inline infix fun ObservableNumberValue.lessEq(other: Double): BooleanBinding =
    Bindings.lessThanOrEqual(this, other)

/** @see NumberExpressionBase.lessThanOrEqualTo */
inline infix fun Double.lessEq(other: ObservableNumberValue): BooleanBinding =
    Bindings.lessThanOrEqual(this, other)

/** @see NumberExpressionBase.lessThanOrEqualTo */
inline infix fun ObservableNumberValue.lessEq(other: Float): BooleanBinding =
    Bindings.lessThanOrEqual(this, other)

/** @see NumberExpressionBase.lessThanOrEqualTo */
inline infix fun Float.lessEq(other: ObservableNumberValue): BooleanBinding =
    Bindings.lessThanOrEqual(this, other)

/** @see NumberExpressionBase.lessThanOrEqualTo */
inline infix fun ObservableNumberValue.lessEq(other: Long): BooleanBinding =
    Bindings.lessThanOrEqual(this, other)

/** @see NumberExpressionBase.lessThanOrEqualTo */
inline infix fun Long.lessEq(other: ObservableNumberValue): BooleanBinding =
    Bindings.lessThanOrEqual(this, other)

/** @see NumberExpressionBase.lessThanOrEqualTo */
inline infix fun ObservableNumberValue.lessEq(other: Int): BooleanBinding =
    Bindings.lessThanOrEqual(this, other)

/** @see NumberExpressionBase.lessThanOrEqualTo */
inline infix fun Int.lessEq(other: ObservableNumberValue): BooleanBinding =
    Bindings.lessThanOrEqual(this, other)


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_MediaView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.media.MediaErrorEvent
import javafx.scene.media.MediaView
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see MediaView.setOnError
 */
public fun MediaView.onError(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MediaErrorEvent) -> Unit
) {
    return setOnError { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/chart/ScatterChartTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.chart.NumberAxis
import javafx.scene.chart.ScatterChart
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class ScatterChartTest : LayoutsTest<KtfxPane, ScatterChart<Number, Number>>() {
    private lateinit var axis1: NumberAxis
    private lateinit var axis2: NumberAxis

    override fun onCreate() {
        super.onCreate()
        axis1 = NumberAxis()
        axis2 = NumberAxis(1.0, 2.0, 3.0)
    }

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = scatterChart(axis1, axis2) { }
    override fun KtfxPane.child2() = scatterChart(axis1, axis2)
    override fun KtfxPane.child3() = scatterChart(axis1, axis2) { }

    override fun ScatterChart<Number, Number>.testDefaultValues() {
        assertEquals(axis1, xAxis)
        assertEquals(axis2, yAxis)
        assertThat(data).isEmpty()
    }
}

<|start_filename|>thirdparty/jfoenix-coroutines/tests/src/com/jfoenix/controls/JFXDialogTest.kt<|end_filename|>
package ktfx.jfoenix.coroutines

import com.jfoenix.controls.JFXDialog
import com.jfoenix.controls.events.JFXDialogEvent
import kotlinx.coroutines.Dispatchers
import ktfx.jfoenix.test.BaseJFXDialogTest

class JFXDialogTest : BaseJFXDialogTest() {

    override fun JFXDialog.callOnDialogClosed(action: (JFXDialogEvent) -> Unit) =
        onDialogClosed(Dispatchers.Unconfined) { action(it) }

    override fun JFXDialog.callOnDialogOpened(action: (JFXDialogEvent) -> Unit) =
        onDialogOpened(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>thirdparty/jfoenix-layouts/src/com/jfoenix/controls/KtfxJFXMasonryPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXMasonryPane
import javafx.scene.Node
import ktfx.layouts.NodeManager
import kotlin.contracts.ExperimentalContracts

/**
 * [JFXMasonryPane] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxJFXMasonryPane : JFXMasonryPane(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { children += it }
}


<|start_filename|>ktfx-coroutines/src/javafx/collections/ObservableArray.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxCoroutinesKt")

package ktfx.coroutines

import javafx.collections.ArrayChangeListener
import javafx.collections.ObservableArray
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch

/** Add a listener to this observable array. */
fun <T : ObservableArray<T>> ObservableArray<T>.listener(
    context: kotlin.coroutines.CoroutineContext = Dispatchers.JavaFx,
    listener: suspend CoroutineScope.(array: T, changed: Boolean, from: Int, to: Int) -> Unit
): ArrayChangeListener<T> = ArrayChangeListener<T> { array, changed, from, to ->
    GlobalScope.launch(context) { listener(array, changed, from, to) }
}.also { addListener(it) }


<|start_filename|>ktfx-commons/tests/src/ktfx/text/FontTest.kt<|end_filename|>
package ktfx.text

import javafx.scene.text.Font
import kotlin.test.Test
import kotlin.test.assertEquals

class FontTest {

    @Test
    fun pt() {
        assertEquals(Font.font(12.0), 12.pt)
        assertEquals(Font.font(18.0), 18.0.pt)
    }

    @Test
    fun fontOf() {
        val font1 = fontOf("Arial", size = 12)
        assertEquals("Arial", font1.family)
        assertEquals(12.0, font1.size)
        val font2 = fontOf("Arial", size = 18.0)
        assertEquals("Arial", font2.family)
        assertEquals(18.0, font2.size)
    }
}


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_TreeTableColumn.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.control.TreeTableColumn
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see TreeTableColumn.setOnEditStart
 */
public fun <S, T> TreeTableColumn<S, T>.onEditStart(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(TreeTableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditStart { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TreeTableColumn.setOnEditCommit
 */
public fun <S, T> TreeTableColumn<S, T>.onEditCommit(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(TreeTableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditCommit { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TreeTableColumn.setOnEditCancel
 */
public fun <S, T> TreeTableColumn<S, T>.onEditCancel(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(TreeTableColumn.CellEditEvent<S, T>) -> Unit
) {
    return setOnEditCancel { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/SplitMenuButtonTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.control.SplitMenuButton
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.Test
import kotlin.test.assertEquals

class SplitMenuButtonTest : LayoutsTest<KtfxPane, SplitMenuButton>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = splitMenuButton { }
    override fun KtfxPane.child2() = splitMenuButton()
    override fun KtfxPane.child3() = splitMenuButton { }

    @Test
    fun stringInvocation() {
        splitMenuButton {
            assertThat(items).isEmpty()
            menuItem("Hello")
            "World" {
            }
            assertEquals(2, items.size)
        }
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/src/com/jfoenix/controls/KtfxJFXTabPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTabPane
import javafx.scene.Node
import javafx.scene.control.Tab
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.KtfxTab
import ktfx.layouts.TabManager
import ktfx.layouts.tab
import kotlin.contracts.ExperimentalContracts

/**
 * [JFXTabPane] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxJFXTabPane : JFXTabPane(), TabManager {

    final override fun <C : Tab> addChild(child: C): C = child.also { tabs += it }

    /** Call [TabManager.tab] by string invocation. */
    inline operator fun String.invoke(
        graphic: Node? = null,
        configuration: (@KtfxLayoutDslMarker KtfxTab).() -> Unit
    ): Tab = tab(this, graphic, configuration)
}


<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/controls/ValidationSupport.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.controls

import javafx.scene.control.Control
import org.controlsfx.validation.Severity
import org.controlsfx.validation.ValidationSupport
import org.controlsfx.validation.Validator

private lateinit var support: ValidationSupport
private val singletonSupport: ValidationSupport
    get() {
        if (!::support.isInitialized) {
            support = ValidationSupport()
        }
        return support
    }

/** Set control's required flag. */
inline var Control.isValidationRequired: Boolean
    get() = ValidationSupport.isRequired(this)
    set(value) = ValidationSupport.setRequired(this, value)

/** Register empty validation. */
fun <T> Control.registerEmptyValidator(
    message: String,
    severity: Severity = Severity.ERROR,
    required: Boolean = true,
    support: ValidationSupport = singletonSupport
): Boolean = support.registerValidator(this, required, Validator.createEmptyValidator<T>(message, severity))

/** Register equals validation. */
fun <T> Control.registerEqualsValidator(
    message: String,
    collection: Collection<T>,
    severity: Severity = Severity.ERROR,
    required: Boolean = true,
    support: ValidationSupport = singletonSupport
): Boolean =
    support.registerValidator(this, required, Validator.createEqualsValidator<T>(message, severity, collection))

/** Register predicate validation. */
fun <T> Control.registerPredicateValidator(
    message: String,
    severity: Severity = Severity.ERROR,
    required: Boolean = true,
    support: ValidationSupport = singletonSupport,
    predicate: (T) -> Boolean
): Boolean =
    support.registerValidator(this, required, Validator.createPredicateValidator<T>(predicate, message, severity))

/** Register regex validation. */
fun Control.registerRegexValidator(
    message: String,
    regex: String,
    severity: Severity = Severity.ERROR,
    required: Boolean = true,
    support: ValidationSupport = singletonSupport
): Boolean = support.registerValidator(this, required, Validator.createRegexValidator(message, regex, severity))

/** Register regex validation. */
fun Control.registerRegexValidator(
    message: String,
    regex: Regex,
    severity: Severity = Severity.ERROR,
    required: Boolean = true,
    support: ValidationSupport = singletonSupport
): Boolean =
    support.registerValidator(this, required, Validator.createRegexValidator(message, regex.toPattern(), severity))


<|start_filename|>rulesets/non-commons/src/com/hendraanggrian/ktfx/rules/NonCommonsRuleSetProvider.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.pinterest.ktlint.core.RuleSet
import com.pinterest.ktlint.core.RuleSetProvider

class NonCommonsRuleSetProvider : RuleSetProvider {

    override fun get() = RuleSet(
        "non-commons-ruleset",
        PredefinedPackageRule()
    )
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_CustomMenuItem.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.CustomMenuItem
import kotlin.Boolean
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [CustomMenuItem] to this manager.
 *
 * @return the control added.
 */
public fun MenuItemManager.customMenuItem(content: Node? = null, hideOnClick: Boolean = true):
    CustomMenuItem = customMenuItem(content = content, hideOnClick = hideOnClick) { }

/**
 * Create a [CustomMenuItem] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun customMenuItem(
    content: Node? = null,
    hideOnClick: Boolean = true,
    configuration: (@KtfxLayoutDslMarker CustomMenuItem).() -> Unit
): CustomMenuItem {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomMenuItem(content, hideOnClick)
    child.configuration()
    return child
}

/**
 * Add a [CustomMenuItem] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun MenuItemManager.customMenuItem(
    content: Node? = null,
    hideOnClick: Boolean = true,
    configuration: (@KtfxLayoutDslMarker CustomMenuItem).() -> Unit
): CustomMenuItem {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomMenuItem(content, hideOnClick)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [CustomMenuItem].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledCustomMenuItem(
    content: Node? = null,
    hideOnClick: Boolean = true,
    vararg styleClass: String,
    id: String? = null
): CustomMenuItem = styledCustomMenuItem(
    content = content, hideOnClick = hideOnClick,
    styleClass =
    *styleClass,
    id = id
) { }

/**
 * Add a styled [CustomMenuItem] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun MenuItemManager.styledCustomMenuItem(
    content: Node? = null,
    hideOnClick: Boolean = true,
    vararg styleClass: String,
    id: String? = null
): CustomMenuItem = styledCustomMenuItem(
    content = content, hideOnClick = hideOnClick,
    styleClass =
    *styleClass,
    id = id
) { }

/**
 * Create a styled [CustomMenuItem] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledCustomMenuItem(
    content: Node? = null,
    hideOnClick: Boolean = true,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker CustomMenuItem).() -> Unit
): CustomMenuItem {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomMenuItem(content, hideOnClick)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [CustomMenuItem] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun MenuItemManager.styledCustomMenuItem(
    content: Node? = null,
    hideOnClick: Boolean = true,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker CustomMenuItem).() -> Unit
): CustomMenuItem {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CustomMenuItem(content, hideOnClick)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/BindingsLongTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.booleanPropertyOf
import ktfx.doublePropertyOf
import ktfx.floatPropertyOf
import ktfx.intPropertyOf
import ktfx.longPropertyOf
import ktfx.propertyOf
import ktfx.time.minutes
import kotlin.test.Test
import kotlin.test.assertEquals

class BindingsLongTest {

    @Test
    fun multipleDependencies() {
        val dependency1 = longPropertyOf(1)
        val dependency2 = longPropertyOf(2)
        val binding1 = longBindingOf(dependency1, dependency2) { dependency1.value + dependency2.value }
        assertEquals(3, binding1.value)
        dependency1.value++
        assertEquals(4, binding1.value)

        val dependency3 = longPropertyOf(1)
        val dependency4 = longPropertyOf(2)
        val binding2 = longBindingOf(listOf(dependency3, dependency4)) { dependency3.value + dependency4.value }
        assertEquals(3, binding2.value)
        dependency3.value++
        assertEquals(4, binding2.value)
    }

    @Test
    fun anyDependency() {
        val dependency = propertyOf(1.minutes)
        val binding = dependency.asLong { it?.toMillis()?.toLong() ?: 0 }
        assertEquals(60000, binding.value)
        dependency.value = null
        assertEquals(0, binding.value)
    }

    @Test
    fun booleanDependency() {
        val dependency = booleanPropertyOf()
        val binding = dependency.asLong { if (it) Long.MAX_VALUE else Long.MIN_VALUE }
        assertEquals(Long.MIN_VALUE, binding.value)
        dependency.value = true
        assertEquals(Long.MAX_VALUE, binding.value)
    }

    @Test
    fun doubleDependency() {
        val dependency = doublePropertyOf()
        val binding = dependency.asLong { it.toLong() }
        assertEquals(0, binding.value)
        dependency.value = Double.MAX_VALUE
        assertEquals(Double.MAX_VALUE.toLong(), binding.value)
    }

    @Test
    fun floatDependency() {
        val dependency = floatPropertyOf()
        val binding = dependency.asLong { it.toLong() }
        assertEquals(0, binding.value)
        dependency.value = Float.MAX_VALUE
        assertEquals(Float.MAX_VALUE.toLong(), binding.value)
    }

    @Test
    fun intDependency() {
        val dependency = intPropertyOf()
        val binding = dependency.asLong { it.toLong() }
        assertEquals(0, binding.value)
        dependency.value = Int.MAX_VALUE
        assertEquals(Int.MAX_VALUE.toLong(), binding.value)
    }

    @Test
    fun longDependency() {
        val dependency = longPropertyOf()
        val binding = dependency.asLong { it }
        assertEquals(0, binding.value)
        dependency.value = Long.MAX_VALUE
        assertEquals(Long.MAX_VALUE, binding.value)
    }
}


<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseTableColumnTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.control.TableColumn
import javafx.scene.control.TablePosition
import javafx.scene.control.TableView
import javafx.util.Duration
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseTableColumnTest {
    private lateinit var table: TableView<Duration>
    private lateinit var column: TableColumn<Duration, Long>
    private lateinit var position: TablePosition<Duration, Long>

    abstract fun <S, T> TableColumn<S, T>.callOnEditStart(action: (TableColumn.CellEditEvent<S, T>) -> Unit)
    abstract fun <S, T> TableColumn<S, T>.callOnEditCommit(action: (TableColumn.CellEditEvent<S, T>) -> Unit)
    abstract fun <S, T> TableColumn<S, T>.callOnEditCancel(action: (TableColumn.CellEditEvent<S, T>) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        table = TableView()
        table.columns += TableColumn<Duration, Long>().also { column = it }
        position = TablePosition(table, 0, column)
    }

    @Test
    fun onEditStart() {
        column.callOnEditStart {
            assertEquals(table, it.source)
            assertEquals(position, it.tablePosition)
            assertEquals(TableColumn.editStartEvent<Duration, Long>(), it.eventType)
            assertEquals(0, it.newValue)
        }
        column.onEditStart.handle(
            TableColumn.CellEditEvent(table, position, TableColumn.editStartEvent(), 0)
        )
    }

    @Test
    fun onEditCommit() {
        column.callOnEditCommit {
            assertEquals(table, it.source)
            assertEquals(position, it.tablePosition)
            assertEquals(TableColumn.editCommitEvent<Duration, Long>(), it.eventType)
            assertEquals(0, it.newValue)
        }
        column.onEditCommit.handle(
            TableColumn.CellEditEvent(table, position, TableColumn.editCommitEvent(), 0)
        )
    }

    @Test
    fun onEditCancel() {
        column.callOnEditCancel {
            assertEquals(table, it.source)
            assertEquals(position, it.tablePosition)
            assertEquals(TableColumn.editCancelEvent<Duration, Long>(), it.eventType)
            assertEquals(0, it.newValue)
        }
        column.onEditCancel.handle(
            TableColumn.CellEditEvent(table, position, TableColumn.editCancelEvent(), 0)
        )
    }
}

<|start_filename|>ktfx-commons/src/ktfx/controls/Scene.kt<|end_filename|>
package ktfx.controls

import javafx.scene.Node
import javafx.scene.Scene
import javafx.scene.image.WritableImage

/** Alias of [Scene.lookup] with non-null return and specified type. */
inline fun <reified T : Node> Scene.find(selector: String): T = lookup(selector) as T

/** Take a snapshot of this [Node] returning image it wrote. */
@Suppress("NOTHING_TO_INLINE")
inline fun Scene.capture(): WritableImage = snapshot(null)


<|start_filename|>ktfx-commons/src/ktfx/time/Duration.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.time

import javafx.util.Duration
import java.util.concurrent.TimeUnit
import kotlin.time.DurationUnit
import kotlin.time.ExperimentalTime
import kotlin.time.toDuration

/** Converts this [String] to a duration with the syntax `[number][ms|s|m|h]`. */
inline fun String.toDuration(): Duration = Duration.valueOf(this)

/**
 * Returns a duration equal to this [Int] number of milliseconds.
 * @see kotlin.time.Duration.milliseconds
 */
val Int.milliseconds: Duration get() = toDouble().milliseconds

/**
 * Returns a duration equal to this [Long] number of milliseconds.
 * @see kotlin.time.Duration.milliseconds
 */
val Long.milliseconds: Duration get() = toDouble().milliseconds

/**
 * Returns a duration equal to this [Double] number of milliseconds.
 * @see kotlin.time.Duration.milliseconds
 */
inline val Double.milliseconds: Duration get() = Duration.millis(this)

/**
 * Returns a duration equal to this [Int] number of seconds.
 * @see kotlin.time.Duration.seconds
 */
val Int.seconds: Duration get() = toDouble().seconds

/**
 * Returns a duration equal to this [Long] number of seconds.
 * @see kotlin.time.Duration.seconds
 */
val Long.seconds: Duration get() = toDouble().seconds

/**
 * Returns a duration equal to this [Double] number of seconds.
 * @see kotlin.time.Duration.seconds
 */
inline val Double.seconds: Duration get() = Duration.seconds(this)

/**
 * Returns a duration equal to this [Int] number of minutes.
 * @see kotlin.time.Duration.minutes
 */
val Int.minutes: Duration get() = toDouble().minutes

/**
 * Returns a duration equal to this [Long] number of minutes.
 * @see kotlin.time.Duration.minutes
 */
val Long.minutes: Duration get() = toDouble().minutes

/**
 * Returns a duration equal to this [Double] number of minutes.
 * @see kotlin.time.Duration.minutes
 */
inline val Double.minutes: Duration get() = Duration.minutes(this)

/**
 * Returns a duration equal to this [Int] number of hours.
 * @see kotlin.time.Duration.hours
 */
val Int.hours: Duration get() = toDouble().hours

/**
 * Returns a duration equal to this [Long] number of hours.
 * @see kotlin.time.Duration.hours
 */
val Long.hours: Duration get() = toDouble().hours

/**
 * Returns a duration equal to this [Double] number of hours.
 * @see kotlin.time.Duration.hours
 */
inline val Double.hours: Duration get() = Duration.hours(this)

/**
 * Returns a duration whose value is the sum of this and [other] duration values.
 * @see kotlin.time.Duration.plus
 */
inline operator fun Duration.plus(other: Duration): Duration = add(other)

/**
 * Returns a duration whose value is the difference between this and [other] duration values.
 * @see kotlin.time.Duration.minus
 */
inline operator fun Duration.minus(other: Duration): Duration = subtract(other)

/**
 * Returns a duration whose value is this duration value multiplied by the given [scale] number.
 * @see kotlin.time.Duration.times
 */
operator fun Duration.times(scale: Int): Duration = multiply(scale.toDouble())

/**
 * Returns a duration whose value is this duration value multiplied by the given [scale] number.
 * @see kotlin.time.Duration.times
 */
inline operator fun Duration.times(scale: Double): Duration = multiply(scale)

/**
 * Returns a duration whose value is this duration value divided by the given [scale] number.
 * @see kotlin.time.Duration.div
 */
operator fun Duration.div(scale: Int): Duration = divide(scale.toDouble())

/**
 * Returns a duration whose value is this duration value divided by the given [scale] number.
 * @see kotlin.time.Duration.div
 */
inline operator fun Duration.div(scale: Double): Duration = divide(scale)

/**
 * Returns the negative of this value.
 * @see kotlin.time.Duration.unaryMinus
 */
inline operator fun Duration.unaryMinus(): Duration = negate()

/** Returns this [Duration] as a [kotlin.time.Duration]. */
@ExperimentalTime
inline fun Duration.toKotlinDuration(): kotlin.time.Duration = toMillis().toDuration(DurationUnit.MILLISECONDS)

/** Returns this [kotlin.time.Duration] as a JavaFX [Duration]. */
@ExperimentalTime
inline fun kotlin.time.Duration.toFxDuration(): Duration = Duration(toDouble(TimeUnit.MILLISECONDS))


<|start_filename|>ktfx-listeners/src/javafx/collections/ObservableMap.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.collections.MapChangeListener
import javafx.collections.MapChangeListener.Change
import javafx.collections.ObservableMap

/** Add a listener to this observable map. */
inline fun <K, V> ObservableMap<K, V>.listener(
    noinline listener: (Change<out K, out V>) -> Unit
): MapChangeListener<K, V> = MapChangeListener<K, V>(listener).also { addListener(it) }


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/listeners/ListenersWriter.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.listeners

import com.hendraanggrian.kotlinpoet.buildFileSpec
import com.hendraanggrian.ktfx.codegen.toString
import com.squareup.kotlinpoet.LambdaTypeName
import com.squareup.kotlinpoet.ParameterizedTypeName
import com.squareup.kotlinpoet.STAR
import java.io.File

object ListenersWriter {

    fun write(factory: BaseListenersFactory) {
        println("Generating to ${factory.path}:")
        factory.entries.forEach { classEntry ->
            buildFileSpec(factory.packageName, "_${classEntry.generatedName}") {
                indentSize = 4
                annotations {
                    add<JvmMultifileClass>()
                    JvmName::class { addMember("%S", factory.className) }
                }
                classEntry.functions.forEach { functionEntry ->
                    functions {
                        functionEntry.simpleFunctionName {
                            kdoc.append("@see %T.${functionEntry.functionName}", classEntry.kdocType)
                            receiver = classEntry.receiver

                            if (classEntry.receiver is ParameterizedTypeName) {
                                classEntry.receiver.typeArguments.filter { it != STAR }.forEach {
                                    typeVariables += it.toString()
                                }
                            }

                            returns<Unit>()
                            if (factory.extraFunctionModifier != null) {
                                addModifiers(factory.extraFunctionModifier)
                            }
                            parameters {
                                functionEntry.parameters.forEach(::plusAssign)
                            }

                            appendLine {
                                append("return ")
                                when ("coroutines") {
                                    !in factory.path -> append(
                                        "${functionEntry.functionName}(${parameters.toString(
                                            namedArgument = false,
                                            commaSuffix = false
                                        )})"
                                    )
                                    else -> {
                                        val hasParam = (parameters.last().type as LambdaTypeName)
                                            .parameters.isNotEmpty()
                                        append("${functionEntry.functionName} {")
                                        if (hasParam) {
                                            append(" event ->")
                                        }
                                        append(" GlobalScope.launch(context) { ${parameters.last().name}(")
                                        if (hasParam) {
                                            append("event")
                                        }
                                        append(") } }")
                                    }
                                }
                            }
                        }
                    }
                }
                factory.extraFileConfiguration(this)
            }.writeTo(File(factory.path))
        }
        println("Finished!")
        println()
    }
}

<|start_filename|>ktfx-commons/src/ktfx/cells/TableCells.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.cells

import javafx.beans.value.ObservableValue
import javafx.collections.ObservableList
import javafx.scene.control.TableCell
import javafx.scene.control.TableColumn
import javafx.scene.control.cell.CheckBoxTableCell
import javafx.scene.control.cell.ChoiceBoxTableCell
import javafx.scene.control.cell.ComboBoxTableCell
import javafx.scene.control.cell.ProgressBarTableCell
import javafx.scene.control.cell.TextFieldTableCell
import javafx.util.StringConverter

/**
 * Sets a [CheckBoxTableCell] factory for use in this [TableColumn].
 */
inline fun <S> TableColumn<S, Boolean>.checkBoxCellFactory(): Unit =
    setCellFactory(CheckBoxTableCell.forTableColumn(this))

/**
 * Sets a [CheckBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param selectedPropertyProvider A provider that, given an object from `TableColumn<S,T>`,
 *  will return an `ObservableValue<Boolean>` that represents whether the given item is selected or not.
 */
inline fun <S, T> TableColumn<S, T>.checkBoxCellFactory(
    noinline selectedPropertyProvider: (Int) -> ObservableValue<Boolean>
): Unit = setCellFactory(CheckBoxTableCell.forTableColumn(selectedPropertyProvider))

/**
 * Sets a [CheckBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param selectedPropertyProvider A provider that, given an object from `TableColumn<S,T>`,
 *  will return an `ObservableValue<Boolean>` that represents whether the given item is selected or not.
 */
inline fun <S, T> TableColumn<S, T>.checkBoxCellFactory(
    converter: StringConverter<T>,
    noinline selectedPropertyProvider: (Int) -> ObservableValue<Boolean>
): Unit = setCellFactory(CheckBoxTableCell.forTableColumn(selectedPropertyProvider, converter))

/**
 * Sets a [CheckBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param showLabel In some cases, it may be desirable to show a label in
 *  the TableCell beside the [javafx.scene.control.CheckBox].
 * @param selectedPropertyProvider A provider that, given an object from `TableColumn<S,T>`,
 *  will return an `ObservableValue<Boolean>` that represents whether the given item is selected or not.
 */
inline fun <S, T> TableColumn<S, T>.checkBoxCellFactory(
    showLabel: Boolean,
    noinline selectedPropertyProvider: (Int) -> ObservableValue<Boolean>
): Unit = setCellFactory(CheckBoxTableCell.forTableColumn(selectedPropertyProvider, showLabel))

/**
 * Sets a [CheckBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <S, T> TableColumn<S, T>.choiceBoxCellFactory(
    vararg items: T
): Unit = setCellFactory(ChoiceBoxTableCell.forTableColumn(*items))

/**
 * Sets a [ChoiceBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <S, T> TableColumn<S, T>.choiceBoxCellFactory(
    converter: StringConverter<T>,
    vararg items: T
): Unit = setCellFactory(ChoiceBoxTableCell.forTableColumn(converter, *items))

/**
 * Sets a [ChoiceBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <S, T> TableColumn<S, T>.choiceBoxCellFactory(
    items: ObservableList<T>
): Unit = setCellFactory(ChoiceBoxTableCell.forTableColumn(items))

/**
 * Sets a [ChoiceBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <S, T> TableColumn<S, T>.choiceBoxCellFactory(
    converter: StringConverter<T>,
    items: ObservableList<T>
): Unit = setCellFactory(ChoiceBoxTableCell.forTableColumn(converter, items))

/**
 * Sets a [ComboBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <S, T> TableColumn<S, T>.comboBoxCellFactory(
    vararg items: T
): Unit = setCellFactory(ComboBoxTableCell.forTableColumn(*items))

/**
 * Sets a [ComboBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <S, T> TableColumn<S, T>.comboBoxCellFactory(
    converter: StringConverter<T>,
    vararg items: T
): Unit = setCellFactory(ComboBoxTableCell.forTableColumn(converter, *items))

/**
 * Sets a [ComboBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <S, T> TableColumn<S, T>.comboBoxCellFactory(
    items: ObservableList<T>
): Unit = setCellFactory(ComboBoxTableCell.forTableColumn(items))

/**
 * Sets a [ComboBoxTableCell] factory for use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <S, T> TableColumn<S, T>.comboBoxCellFactory(
    converter: StringConverter<T>,
    items: ObservableList<T>
): Unit = setCellFactory(ComboBoxTableCell.forTableColumn(converter, items))

/**
 * Sets a [ProgressBarTableCell] factory for use in this [TableColumn].
 */
inline fun <S> TableColumn<S, Double>.progressBarCellFactory(): Unit =
    setCellFactory(ProgressBarTableCell.forTableColumn<S>())

/**
 * Sets a [TextFieldTableCell] factory for use in this [TableColumn].
 */
inline fun <S> TableColumn<S, String>.textFieldCellFactory(): Unit =
    setCellFactory(TextFieldTableCell.forTableColumn())

/**
 * Sets a [TextFieldTableCell] factory for use in this [TableColumn].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 */
inline fun <S, T> TableColumn<S, T>.textFieldCellFactory(
    converter: StringConverter<T>
): Unit = setCellFactory(TextFieldTableCell.forTableColumn(converter))

/**
 * Sets a custom cell factory to use in this [TableColumn].
 * @param T The type of the elements contained within the [TableColumn].
 * @param configuration custom initialization block that configures [KtfxTableCell].
 */
fun <S, T> TableColumn<S, T>.cellFactory(
    configuration: KtfxTableCell<S, T>.(TableColumn<S, T>) -> Unit
): Unit = setCellFactory { KtfxTableCell<S, T>().apply { configuration(it) } }

/** Custom [TableCell] configurator class. */
class KtfxTableCell<S, T> : TableCell<S, T>(), KtfxCell<T> {
    private var onEditStart: (() -> Unit)? = null
    private var onEditCommit: ((T?) -> Unit)? = null
    private var onEditCancel: (() -> Unit)? = null
    private var onUpdate: ((T?, empty: Boolean) -> Unit)? = null

    override fun onEditStart(action: () -> Unit) {
        onEditStart = action
    }

    override fun startEdit() {
        super.startEdit()
        onEditStart?.invoke()
    }

    override fun onEditCommit(action: (T?) -> Unit) {
        onEditCommit = action
    }

    override fun commitEdit(newValue: T?) {
        super.commitEdit(newValue)
        onEditCommit?.invoke(newValue)
    }

    override fun onEditCancel(action: () -> Unit) {
        onEditCancel = action
    }

    override fun cancelEdit() {
        super.cancelEdit()
        onEditCancel?.invoke()
    }

    override fun onUpdate(action: (T?, empty: Boolean) -> Unit) {
        onUpdate = action
    }

    override fun updateItem(item: T?, empty: Boolean) {
        super.updateItem(item, empty)
        onUpdate?.invoke(item, empty)
    }
}


<|start_filename|>testing/listeners-coroutines/src/javafx/scene/control/BaseChoiceBoxTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.ChoiceBox
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseChoiceBoxTest {
    private lateinit var choice: ChoiceBox<String>

    abstract fun <E> ChoiceBox<E>.callOnAction(action: (ActionEvent) -> Unit)
    abstract fun <E> ChoiceBox<E>.callOnShowing(action: (Event) -> Unit)
    abstract fun <E> ChoiceBox<E>.callOnShown(action: (Event) -> Unit)
    abstract fun <E> ChoiceBox<E>.callOnHiding(action: (Event) -> Unit)
    abstract fun <E> ChoiceBox<E>.callOnHidden(action: (Event) -> Unit)

    @BeforeTest
    fun start() {
        initToolkit()
        choice = ChoiceBox()
    }

    @Test
    fun onAction() {
        choice.callOnAction {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
        }
        choice.onAction.handle(ActionEvent(this, FakeEventTarget))
    }

    @Test
    fun onShowing() {
        choice.callOnShowing {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        choice.onShowing.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onShown() {
        choice.callOnShown {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        choice.onShown.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onHiding() {
        choice.callOnHiding {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        choice.onHiding.handle(Event(this, FakeEventTarget, Event.ANY))
    }

    @Test
    fun onHidden() {
        choice.callOnHidden {
            assertEquals(this, it.source)
            assertEquals(FakeEventTarget, it.target)
            assertEquals(Event.ANY, it.eventType)
        }
        choice.onHidden.handle(Event(this, FakeEventTarget, Event.ANY))
    }
}

<|start_filename|>ktfx-commons/src/ktfx/controls/SwingUtils.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controls

import javafx.embed.swing.SwingFXUtils
import javafx.scene.image.Image
import javafx.scene.image.WritableImage
import java.awt.image.BufferedImage

/**
 * Snapshots the specified [BufferedImage] and stores a copy of its pixels into a JavaFX [Image] object,
 * creating a new object if needed.
 */
inline fun BufferedImage.toFxImage(wimg: WritableImage? = null): WritableImage = SwingFXUtils.toFXImage(this, wimg)

/**
 * Snapshots the specified JavaFX [Image] object and stores a copy of its pixels into a [BufferedImage] object,
 * creating a new object if needed.
 */
inline fun Image.toSwingImage(bimg: BufferedImage? = null): BufferedImage = SwingFXUtils.fromFXImage(this, bimg)


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Sphere.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.Sphere
import kotlin.Double
import kotlin.Int
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [Sphere] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.sphere(radius: Double = 1.0, division: Int = 64): Sphere = sphere(
    radius =
    radius,
    division = division
) { }

/**
 * Create a [Sphere] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun sphere(
    radius: Double = 1.0,
    division: Int = 64,
    configuration: (@KtfxLayoutDslMarker Sphere).() -> Unit
): Sphere {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Sphere(radius, division)
    child.configuration()
    return child
}

/**
 * Add a [Sphere] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.sphere(
    radius: Double = 1.0,
    division: Int = 64,
    configuration: (@KtfxLayoutDslMarker Sphere).() -> Unit
): Sphere {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Sphere(radius, division)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Sphere].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledSphere(
    radius: Double = 1.0,
    division: Int = 64,
    vararg styleClass: String,
    id: String? = null
): Sphere = styledSphere(radius = radius, division = division, styleClass = *styleClass, id = id) {
}

/**
 * Add a styled [Sphere] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledSphere(
    radius: Double = 1.0,
    division: Int = 64,
    vararg styleClass: String,
    id: String? = null
): Sphere = styledSphere(radius = radius, division = division, styleClass = *styleClass, id = id) {
}

/**
 * Create a styled [Sphere] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledSphere(
    radius: Double = 1.0,
    division: Int = 64,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Sphere).() -> Unit
): Sphere {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Sphere(radius, division)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Sphere] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledSphere(
    radius: Double = 1.0,
    division: Int = 64,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Sphere).() -> Unit
): Sphere {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Sphere(radius, division)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/layout/GridPaneTest.kt<|end_filename|>
package ktfx.layouts

import com.hendraanggrian.ktfx.test.LayoutsTest
import javafx.scene.layout.GridPane
import ktfx.controls.H_RIGHT
import ktfx.controls.V_BOTTOM
import kotlin.test.Test
import kotlin.test.assertEquals

class GridPaneTest : LayoutsTest<KtfxPane, GridPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = gridPane { }
    override fun KtfxPane.child2() = gridPane()
    override fun KtfxPane.child3() = gridPane { }

    @Test
    fun grid() {
        gridPane {
            val label1 = label().grid(1, 2)
            assertEquals(1, label1.rowIndex)
            assertEquals(2, label1.columnIndex)
            val label2 = label().grid(1 to 3)
            assertEquals(1, label2.rowIndex)
            assertEquals(3, label2.rowSpan)
            val label3 = label().grid(col = 2 to 4)
            assertEquals(2, label3.columnIndex)
            assertEquals(4, label3.columnSpan)
            val label4 = label().grid(1 to 3, 2 to 4)
            assertEquals(1, label4.rowIndex)
            assertEquals(2, label4.columnIndex)
            assertEquals(3, label4.rowSpan)
            assertEquals(4, label4.columnSpan)
        }
    }

    @Test
    fun halign() {
        gridPane {
            val label = label().halign(H_RIGHT)
            assertEquals(H_RIGHT, label.halignment)
        }
    }

    @Test
    fun valign() {
        gridPane {
            val label = label().valign(V_BOTTOM)
            assertEquals(V_BOTTOM, label.valignment)
        }
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/RectangleTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.Rectangle
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class RectangleTest : LayoutsTest<KtfxPane, Rectangle>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = rectangle { }
    override fun KtfxPane.child2() = rectangle()
    override fun KtfxPane.child3() = rectangle { }

    override fun Rectangle.testDefaultValues() {
        assertEquals(0.0, x)
        assertEquals(0.0, y)
        assertEquals(0.0, width)
        assertEquals(0.0, height)
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/StatusBarTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.StatusBar

class StatusBarTest : LayoutsTest<KtfxPane, StatusBar>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = statusBar { }
    override fun KtfxPane.child2() = statusBar()
    override fun KtfxPane.child3() = statusBar { }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXTreeCellTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTreeCell
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXTreeCellTest : LayoutsTest<KtfxPane, JFXTreeCell<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxTreeCell<String> { }
    override fun KtfxPane.child2() = jfxTreeCell<String>()
    override fun KtfxPane.child3() = jfxTreeCell<String> { }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/MenuTest.kt<|end_filename|>
package ktfx.listeners

import javafx.event.Event
import javafx.scene.control.Menu
import com.hendraanggrian.ktfx.test.BaseMenuTest

class MenuTest : BaseMenuTest() {

    override fun Menu.callOnShowing(action: (Event) -> Unit) = onShowing(action)
    override fun Menu.callOnShown(action: (Event) -> Unit) = onShown(action)
    override fun Menu.callOnHiding(action: (Event) -> Unit) = onHiding(action)
    override fun Menu.callOnHidden(action: (Event) -> Unit) = onHidden(action)
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/TreeTableColumnTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.control.TreeTableColumn
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseTreeTableColumnTest

class TreeTableColumnTest : BaseTreeTableColumnTest() {

    override fun <S, T> TreeTableColumn<S, T>.callOnEditStart(action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditStart(Dispatchers.Unconfined) { action(it) }

    override fun <S, T> TreeTableColumn<S, T>.callOnEditCommit(action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditCommit(Dispatchers.Unconfined) { action(it) }

    override fun <S, T> TreeTableColumn<S, T>.callOnEditCancel(action: (TreeTableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditCancel(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/PrefixSelectionChoiceBoxTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.PrefixSelectionChoiceBox

class PrefixSelectionChoiceBoxTest : LayoutsTest<KtfxPane, PrefixSelectionChoiceBox<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = prefixSelectionChoiceBox<String> { }
    override fun KtfxPane.child2() = prefixSelectionChoiceBox<String>()
    override fun KtfxPane.child3() = prefixSelectionChoiceBox<String> { }
}

<|start_filename|>thirdparty/controlsfx-listeners/src/ktfx/controlsfx/listeners/_NotificationPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.listeners

import javafx.event.Event
import org.controlsfx.control.NotificationPane
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see NotificationPane.setOnShowing
 */
public inline fun NotificationPane.onShowing(noinline action: (Event) -> Unit) {
    return setOnShowing(action)
}

/**
 * @see NotificationPane.setOnShown
 */
public inline fun NotificationPane.onShown(noinline action: (Event) -> Unit) {
    return setOnShown(action)
}

/**
 * @see NotificationPane.setOnHiding
 */
public inline fun NotificationPane.onHiding(noinline action: (Event) -> Unit) {
    return setOnHiding(action)
}

/**
 * @see NotificationPane.setOnHidden
 */
public inline fun NotificationPane.onHidden(noinline action: (Event) -> Unit) {
    return setOnHidden(action)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/chart/AreaChartTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.chart.AreaChart
import javafx.scene.chart.NumberAxis
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class AreaChartTest : LayoutsTest<KtfxPane, AreaChart<Number, Number>>() {
    private lateinit var axis1: NumberAxis
    private lateinit var axis2: NumberAxis

    override fun onCreate() {
        super.onCreate()
        axis1 = NumberAxis()
        axis2 = NumberAxis(1.0, 2.0, 3.0)
    }

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = areaChart(axis1, axis2) { }
    override fun KtfxPane.child2() = areaChart(axis1, axis2)
    override fun KtfxPane.child3() = areaChart(axis1, axis2) { }

    override fun AreaChart<Number, Number>.testDefaultValues() {
        assertEquals(axis1, xAxis)
        assertEquals(axis2, yAxis)
        assertThat(data).isEmpty()
    }
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/beans/value/ObservableValueTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.beans.Observable
import javafx.beans.value.ObservableValue
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseObservableValueTest

class ObservableValueTest : BaseObservableValueTest() {

    override fun ObservableValue<String>.callListener(action: (Observable, String, String) -> Unit) {
        listener(Dispatchers.Unconfined) { observable, oldValue, value -> action(observable, oldValue, value) }
    }
}

<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/layouts/Ktfx.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.layouts

import com.hendraanggrian.kotlinpoet.asNullable
import com.hendraanggrian.kotlinpoet.dsl.ParameterSpecHandlerScope
import com.hendraanggrian.kotlinpoet.memberOf
import com.hendraanggrian.kotlinpoet.parameterizedBy
import com.squareup.kotlinpoet.asClassName
import com.hendraanggrian.ktfx.codegen.KTFX_LAYOUTS
import com.hendraanggrian.ktfx.codegen.S
import com.hendraanggrian.ktfx.codegen.T
import com.hendraanggrian.ktfx.codegen.X
import com.hendraanggrian.ktfx.codegen.Y
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.geometry.Orientation
import javafx.scene.Group
import javafx.scene.canvas.Canvas
import javafx.scene.chart.AreaChart
import javafx.scene.chart.Axis
import javafx.scene.chart.BarChart
import javafx.scene.chart.BubbleChart
import javafx.scene.chart.PieChart
import javafx.scene.chart.ScatterChart
import javafx.scene.chart.StackedAreaChart
import javafx.scene.chart.StackedBarChart
import javafx.scene.chart.XYChart
import javafx.scene.control.Accordion
import javafx.scene.control.Button
import javafx.scene.control.ButtonBar
import javafx.scene.control.CheckBox
import javafx.scene.control.CheckMenuItem
import javafx.scene.control.ChoiceBox
import javafx.scene.control.ColorPicker
import javafx.scene.control.ComboBox
import javafx.scene.control.CustomMenuItem
import javafx.scene.control.DatePicker
import javafx.scene.control.Hyperlink
import javafx.scene.control.Label
import javafx.scene.control.ListView
import javafx.scene.control.Menu
import javafx.scene.control.MenuBar
import javafx.scene.control.MenuButton
import javafx.scene.control.MenuItem
import javafx.scene.control.Pagination
import javafx.scene.control.PasswordField
import javafx.scene.control.ProgressBar
import javafx.scene.control.ProgressIndicator
import javafx.scene.control.RadioButton
import javafx.scene.control.RadioMenuItem
import javafx.scene.control.ScrollBar
import javafx.scene.control.ScrollPane
import javafx.scene.control.Separator
import javafx.scene.control.SeparatorMenuItem
import javafx.scene.control.Slider
import javafx.scene.control.Spinner
import javafx.scene.control.SplitMenuButton
import javafx.scene.control.SplitPane
import javafx.scene.control.Tab
import javafx.scene.control.TabPane
import javafx.scene.control.TableView
import javafx.scene.control.TextArea
import javafx.scene.control.TextField
import javafx.scene.control.TitledPane
import javafx.scene.control.ToggleButton
import javafx.scene.control.ToolBar
import javafx.scene.control.TreeTableView
import javafx.scene.control.TreeView
import javafx.scene.image.Image
import javafx.scene.image.ImageView
import javafx.scene.layout.AnchorPane
import javafx.scene.layout.BorderPane
import javafx.scene.layout.FlowPane
import javafx.scene.layout.GridPane
import javafx.scene.layout.HBox
import javafx.scene.layout.Pane
import javafx.scene.layout.Region
import javafx.scene.layout.StackPane
import javafx.scene.layout.TilePane
import javafx.scene.layout.VBox
import javafx.scene.media.MediaPlayer
import javafx.scene.media.MediaView
import javafx.scene.paint.Paint
import javafx.scene.shape.Arc
import javafx.scene.shape.ArcTo
import javafx.scene.shape.Box
import javafx.scene.shape.Circle
import javafx.scene.shape.ClosePath
import javafx.scene.shape.CubicCurve
import javafx.scene.shape.CubicCurveTo
import javafx.scene.shape.Cylinder
import javafx.scene.shape.Ellipse
import javafx.scene.shape.HLineTo
import javafx.scene.shape.Line
import javafx.scene.shape.LineTo
import javafx.scene.shape.Mesh
import javafx.scene.shape.MeshView
import javafx.scene.shape.MoveTo
import javafx.scene.shape.Path
import javafx.scene.shape.Polygon
import javafx.scene.shape.Polyline
import javafx.scene.shape.QuadCurve
import javafx.scene.shape.QuadCurveTo
import javafx.scene.shape.Rectangle
import javafx.scene.shape.SVGPath
import javafx.scene.shape.Sphere
import javafx.scene.shape.VLineTo
import javafx.scene.text.Text
import javafx.scene.text.TextFlow
import javafx.scene.web.WebView

val LayoutsFactory.Companion.JavaFx: LayoutsFactory
    get() = object : LayoutsFactory("ktfx-layouts/src", KTFX_LAYOUTS, "KtfxLayoutsKt") {
        init {
            // javafx.scene
            Group::class(customClass = true)

            // javafx.scene.canvas
            Canvas::class { width(); height() }

            // javafx.scene.chart
            AreaChart::class(X, Y) { xyChartParameters() }
            BarChart::class(X, Y) { xyChartParameters(); "categoryGap"<Double> { defaultValue("10.0") } }
            BubbleChart::class(X, Y) { xyChartParameters() }
            PieChart::class {
                "data"(ObservableList::class.parameterizedBy(PieChart.Data::class)) {
                    defaultValue("%M()", FXCollections::class.memberOf("observableArrayList"))
                }
            }
            ScatterChart::class(X, Y) { xyChartParameters() }
            StackedAreaChart::class(X, Y) { xyChartParameters() }
            StackedBarChart::class(X, Y) { xyChartParameters() }

            // javafx.scene.control
            Accordion::class(customClass = true)
            Button::class { text(); graphic() }
            ButtonBar::class(customClass = true) { "buttonOrder"(String::class.asNullable()) { defaultValue("null") } }
            CheckBox::class { text() }
            CheckMenuItem::class { text(); graphic() }
            ChoiceBox::class(T) { items(T) }
            ColorPicker::class { color() }
            ComboBox::class(T) { items(T) }
            CustomMenuItem::class { content(); "hideOnClick"<Boolean> { defaultValue("true") } }
            DatePicker::class { date() }
            Hyperlink::class{ text(); graphic() }
            Label::class{ text(); graphic() }
            ListView::class(T) { items(T) }
            Menu::class(customClass = true) { emptyText(); graphic() }
            MenuBar::class(customClass = true)
            MenuButton::class(customClass = true) { text(); graphic() }
            MenuItem::class { text(); graphic() }
            Pagination::class {
                "pageCount"<Int> { defaultValue("%M", Pagination::class.memberOf("INDETERMINATE")) }
                "currentPageIndex"<Int> { defaultValue("0") }
            }
            PasswordField::class()
            ProgressBar::class { progress() }
            ProgressIndicator::class { progress() }
            RadioButton::class { text() }
            RadioMenuItem::class { text(); graphic() }
            ScrollBar::class()
            ScrollPane::class(customClass = true) { content() }
            Separator::class { orientation() }
            SeparatorMenuItem::class()
            Slider::class { slider("0.0") }
            Spinner::class(T)
            SplitMenuButton::class(customClass = true)
            SplitPane::class(customClass = true)
            Tab::class(customClass = true) { text(); content() }
            TableView::class(S) { items(S) }
            TabPane::class(customClass = true)
            TextArea::class { emptyText() }
            TextField::class { emptyText() }
            TitledPane::class(customClass = true) { "title"(String::class.asNullable()) { defaultValue("null") } }
            ToggleButton::class { text(); graphic() }
            ToolBar::class(customClass = true)
            TreeTableView::class(S) { treeItem("root", S) }
            TreeView::class(T) { treeItem("root", T) }

            // javafx.scene.image
            ImageView::class { add("image", Image::class.asNullable()) { defaultValue("null") } }
            ImageView::class { add<String>("imageUrl") }

            // javafx.scene.media
            MediaView::class { add("mediaPlayer", MediaPlayer::class.asNullable()) { defaultValue("null") } }

            // javafx.scene.layout
            AnchorPane::class(customClass = true)
            BorderPane::class(customClass = true)
            FlowPane::class(customClass = true) { orientation(); add<Double>("hgap"); add<Double>("vgap") }
            FlowPane::class(customClass = true) { orientation(); "gap"<Double> { defaultValue("0.0") } }
            GridPane::class(customClass = true)
            HBox::class(customClass = true) { spacing() }
            Pane::class(customClass = true)
            Region::class()
            StackPane::class(customClass = true)
            TilePane::class(customClass = true) { orientation(); add<Double>("hgap"); add<Double>("vgap") }
            TilePane::class(customClass = true) { orientation(); "gap"<Double> { defaultValue("0.0") } }
            VBox::class(customClass = true) { spacing() }

            // javafx.scene.shape
            Arc::class {
                centerXY(); radiusXY()
                "startAngle"<Double> { defaultValue("0.0") }
                "length"<Double> { defaultValue("0.0") }
            }
            ArcTo::class {
                radiusXY()
                "xAxisRotation"<Double> { defaultValue("0.0") }
                x(); y()
                "largeArcFlag"<Boolean> { defaultValue("false") }
                "sweepFlag"<Boolean> { defaultValue("false") }
            }
            Box::class {
                "width"<Double> { defaultValue("%M", Box::class.memberOf("DEFAULT_SIZE")) }
                "height"<Double> { defaultValue("%M", Box::class.memberOf("DEFAULT_SIZE")) }
                "depth"<Double> { defaultValue("%M", Box::class.memberOf("DEFAULT_SIZE")) }
            }
            Circle::class { centerXY(); radius(0.0); fill() }
            ClosePath::class()
            CubicCurve::class { startXY(); controlXY1(); controlXY2(); endXY() }
            CubicCurveTo::class { controlXY1(); controlXY2(); x(); y(); }
            Cylinder::class { radius(1.0); "height"<Double> { defaultValue("2.0") }; division() }
            Ellipse::class { centerXY(); radiusXY() }
            HLineTo::class { x() }
            Line::class { centerXY(); endXY() }
            LineTo::class { x(); y() }
            MeshView::class { "mesh"(Mesh::class.asClassName().asNullable()) { defaultValue("null") } }
            MoveTo::class { x(); y() }
            Path::class(customClass = true)
            Polygon::class() // points param not included since vararg is reserved
            Polyline::class() // points param not included since vararg is reserved
            QuadCurve::class { startXY(); controlXY(); endXY() }
            QuadCurveTo::class { controlXY(); x(); y() }
            Rectangle::class { x(); y(); width(); height() }
            Sphere::class { radius(1.0); division() }
            SVGPath::class()
            VLineTo::class { y() }

            // javafx.scene.text
            Text::class { text() }
            TextFlow::class(customClass = true)

            // javafx.scene.web
            WebView::class()
        }

        fun ParameterSpecHandlerScope.emptyText() = "text"<String> { defaultValue("\"\"") }

        fun ParameterSpecHandlerScope.orientation() =
            "orientation"<Orientation> { defaultValue("%M", Orientation::class.memberOf("HORIZONTAL")) }

        fun ParameterSpecHandlerScope.spacing() = "spacing"<Double> { defaultValue("0.0") }
        fun ParameterSpecHandlerScope.width() = "width"<Double> { defaultValue("0.0") }
        fun ParameterSpecHandlerScope.height() = "height"<Double> { defaultValue("0.0") }

        fun ParameterSpecHandlerScope.xyChartParameters() {
            add("x", Axis::class.parameterizedBy(X))
            add("y", Axis::class.parameterizedBy(Y))
            "data"(ObservableList::class.parameterizedBy(XYChart.Series::class.parameterizedBy(X, Y))) {
                defaultValue("%M()", FXCollections::class.memberOf("observableArrayList"))
            }
        }

        fun ParameterSpecHandlerScope.x() = "x"<Double> { defaultValue("0.0") }
        fun ParameterSpecHandlerScope.y() = "y"<Double> { defaultValue("0.0") }

        fun ParameterSpecHandlerScope.startXY() {
            "startX"<Double> { defaultValue("0.0") }
            "startY"<Double> { defaultValue("0.0") }
        }

        fun ParameterSpecHandlerScope.endXY() {
            "endX"<Double> { defaultValue("0.0") }
            "endY"<Double> { defaultValue("0.0") }
        }

        fun ParameterSpecHandlerScope.centerXY() {
            "centerX"<Double> { defaultValue("0.0") }
            "centerY"<Double> { defaultValue("0.0") }
        }

        fun ParameterSpecHandlerScope.radiusXY() {
            "radiusX"<Double> { defaultValue("0.0") }
            "radiusY"<Double> { defaultValue("0.0") }
        }

        fun ParameterSpecHandlerScope.radius(radius: Double) = "radius"<Double> { defaultValue("$radius") }

        fun ParameterSpecHandlerScope.fill() = "fill"(Paint::class.asNullable()) { defaultValue("null") }

        fun ParameterSpecHandlerScope.controlXY() {
            "controlX"<Double> { defaultValue("0.0") }
            "controlY"<Double> { defaultValue("0.0") }
        }

        fun ParameterSpecHandlerScope.controlXY1() {
            "controlX1"<Double> { defaultValue("0.0") }
            "controlY1"<Double> { defaultValue("0.0") }
        }

        fun ParameterSpecHandlerScope.controlXY2() {
            "controlX2"<Double> { defaultValue("0.0") }
            "controlY2"<Double> { defaultValue("0.0") }
        }

        fun ParameterSpecHandlerScope.division() = "division"<Int> { defaultValue("64") }
    }

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Polyline.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.Polyline
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [Polyline] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.polyline(): Polyline = polyline() { }

/**
 * Create a [Polyline] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun polyline(configuration: (@KtfxLayoutDslMarker Polyline).() -> Unit): Polyline {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Polyline()
    child.configuration()
    return child
}

/**
 * Add a [Polyline] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.polyline(configuration: (@KtfxLayoutDslMarker Polyline).() -> Unit):
    Polyline {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Polyline()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Polyline].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledPolyline(vararg styleClass: String, id: String? = null): Polyline =
    styledPolyline(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [Polyline] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledPolyline(vararg styleClass: String, id: String? = null): Polyline =
    styledPolyline(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [Polyline] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledPolyline(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Polyline).() -> Unit
): Polyline {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Polyline()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Polyline] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledPolyline(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Polyline).() -> Unit
): Polyline {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Polyline()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-listeners/tests/src/javafx/collections/ObservableSetTest.kt<|end_filename|>
package ktfx.listeners

import javafx.collections.ObservableSet
import javafx.collections.SetChangeListener
import com.hendraanggrian.ktfx.test.BaseObservableSetTest

class ObservableSetTest : BaseObservableSetTest() {

    override fun <E> ObservableSet<E>.callListener(action: (SetChangeListener.Change<out E>) -> Unit) {
        listener(action)
    }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_TextField.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.TextField
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [TextField] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.textField(text: String = ""): TextField = textField(text = text) { }

/**
 * Create a [TextField] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun textField(
    text: String = "",
    configuration: (@KtfxLayoutDslMarker TextField).() ->    
    Unit
): TextField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TextField(text)
    child.configuration()
    return child
}

/**
 * Add a [TextField] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.textField(
    text: String = "",
    configuration: (
        @KtfxLayoutDslMarker    
        TextField
    ).() -> Unit
): TextField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TextField(text)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [TextField].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledTextField(
    text: String = "",
    vararg styleClass: String,
    id: String? = null
): TextField = styledTextField(text = text, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [TextField] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledTextField(
    text: String = "",
    vararg styleClass: String,
    id: String? = null
): TextField = styledTextField(text = text, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [TextField] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledTextField(
    text: String = "",
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker TextField).() -> Unit
): TextField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TextField(text)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [TextField] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledTextField(
    text: String = "",
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker TextField).() -> Unit
): TextField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TextField(text)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_Line.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.Line
import kotlin.Double
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [Line] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.line(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0
): Line = line(centerX = centerX, centerY = centerY, endX = endX, endY = endY) { }

/**
 * Create a [Line] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun line(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker Line).() -> Unit
): Line {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Line(centerX, centerY, endX, endY)
    child.configuration()
    return child
}

/**
 * Add a [Line] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.line(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker Line).() -> Unit
): Line {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Line(centerX, centerY, endX, endY)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [Line].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledLine(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): Line = styledLine(
    centerX = centerX, centerY = centerY, endX = endX, endY = endY,
    styleClass =
    *styleClass,
    id = id
) { }

/**
 * Add a styled [Line] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledLine(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null
): Line = styledLine(
    centerX = centerX, centerY = centerY, endX = endX, endY = endY,
    styleClass =
    *styleClass,
    id = id
) { }

/**
 * Create a styled [Line] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledLine(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Line).() -> Unit
): Line {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Line(centerX, centerY, endX, endY)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [Line] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledLine(
    centerX: Double = 0.0,
    centerY: Double = 0.0,
    endX: Double = 0.0,
    endY: Double = 0.0,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker Line).() -> Unit
): Line {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = Line(centerX, centerY, endX, endY)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/src/ktfx/controls/GridConstraints.kt<|end_filename|>
@file:OptIn(ExperimentalContracts::class)

package ktfx.controls

import javafx.collections.ObservableList
import javafx.scene.layout.ColumnConstraints
import javafx.scene.layout.GridPane
import javafx.scene.layout.RowConstraints
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
 * Configure [GridPane] row constraints.
 * @param configuration the configuration block.
 */
fun GridPane.rowConstraints(configuration: RowConstraintsScope.() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    object : RowConstraintsScope {
        override val constraints: ObservableList<RowConstraints> get() = rowConstraints
    }.configuration()
}

/**
 * Configure [GridPane] column constraints.
 * @param configuration the configuration block.
 */
fun GridPane.columnConstraints(configuration: ColumnConstraintsScope.() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    object : ColumnConstraintsScope {
        override val constraints: ObservableList<ColumnConstraints> get() = columnConstraints
    }.configuration()
}

/** [RowConstraints] configurator interface. */
interface RowConstraintsScope {

    /** Constraints of this scope. */
    val constraints: ObservableList<RowConstraints>

    /** Add a default [RowConstraints], returning the constraints added. */
    fun append(): RowConstraints = RowConstraints().also { constraints += it }

    /** Add a [RowConstraints] using [configuration] block, returning the constraints added. */
    fun append(configuration: RowConstraints.() -> Unit): RowConstraints = RowConstraints().also {
        it.configuration()
        constraints += it
    }
}

/** [ColumnConstraints] configurator interface. */
interface ColumnConstraintsScope {

    /** Constraints of this scope. */
    val constraints: ObservableList<ColumnConstraints>

    /** Add a default [ColumnConstraints], returning the constraints added. */
    fun append(): ColumnConstraints = ColumnConstraints().also { constraints += it }

    /** Add a [ColumnConstraints] using [configuration] block, returning the constraints added. */
    fun append(configuration: ColumnConstraints.() -> Unit): ColumnConstraints = ColumnConstraints().also {
        it.configuration()
        constraints += it
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/SeparatorMenuItemTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.SeparatorMenuItem
import com.hendraanggrian.ktfx.test.LayoutsTest

class SeparatorMenuItemTest : LayoutsTest<KtfxMenu, SeparatorMenuItem>() {

    override fun manager() = KtfxMenu("", null)
    override fun KtfxMenu.childCount() = items.size
    override fun child1() = separatorMenuItem { }
    override fun KtfxMenu.child2() = separatorMenuItem()
    override fun KtfxMenu.child3() = separatorMenuItem { }
}

<|start_filename|>ktfx-layouts/src/javafx/scene/layout/KtfxBorderPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.layouts

import javafx.geometry.Insets
import javafx.geometry.Pos
import javafx.scene.Node
import javafx.scene.layout.BorderPane
import kotlin.contracts.ExperimentalContracts

/**
 * [BorderPane] with dynamic-layout dsl support.
 * Invoking dsl will only set its center. There is currently no way to configure other areas (top, left, right, bottom) with dsl.
 * Instead, create an instance and set it manually (e.g: `left = ktfx.layouts.label()`).
 */
open class KtfxBorderPane : BorderPane(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { center = it }

    /** Children alignment in this layout. */
    inline var Node.alignment: Pos?
        @JvmName("getAlignment2") get() = getAlignment(this)
        @JvmName("setAlignment2") set(value) = setAlignment(this, value)

    /** Configure [alignment] fluidly. */
    fun <C : Node> C.align(pos: Pos): C {
        alignment = pos
        return this
    }

    /** Children margin in this layout. */
    inline var Node.margin: Insets?
        @JvmName("getMargin2") get() = getMargin(this)
        @JvmName("setMargin2") set(value) = setMargin(this, value)

    /** Configure [margin] fluidly. */
    fun <C : Node> C.margin(insets: Insets): C {
        margin = insets
        return this
    }

    /** Clear children constraints. */
    @JvmName("clearConstraints2")
    inline fun Node.clearConstraints(): Unit = clearConstraints(this)
}


<|start_filename|>testing/core/src/com/hendraanggrian/ktfx/test/JavaFXThreadRule.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.application.Platform
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutionException

/**
 * A test rule that ensures that JavaFX tests run on the main UI thread.
 *
 * @see <a href="http://andrewtill.blogspot.com/2012/10/junit-rule-for-javafx-controller-testing.html">WONTFIX: JUnit
 * Rule for JavaFX Controller Testing</a>
 */
class JavaFXThreadRule : TestRule {

    override fun apply(statement: Statement, description: Description?): Statement? {
        return object : Statement() {
            @Throws(Throwable::class)
            override fun evaluate() {
                val statementFuture = CompletableFuture<Void?>()
                Platform.runLater {
                    try {
                        statement.evaluate()
                        statementFuture.complete(null)
                    } catch (throwable: Throwable) {
                        statementFuture.completeExceptionally(throwable)
                    }
                }
                try {
                    statementFuture.get()
                } catch (e: ExecutionException) {
                    throw e.cause!!
                }
            }
        }
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXDrawersStackTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXDrawersStack
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXDrawersStackTest : LayoutsTest<KtfxPane, JFXDrawersStack>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxDrawersStack { }
    override fun KtfxPane.child2() = jfxDrawersStack()
    override fun KtfxPane.child3() = jfxDrawersStack { }
}

<|start_filename|>thirdparty/controlsfx-coroutines/tests/src/org/controlsfx/control/HyperlinkLabelTest.kt<|end_filename|>
package ktfx.controlsfx.coroutines

import javafx.event.ActionEvent
import kotlinx.coroutines.Dispatchers
import ktfx.controlsfx.test.BaseHyperlinkLabelTest
import org.controlsfx.control.HyperlinkLabel

class HyperlinkLabelTest : BaseHyperlinkLabelTest() {

    override fun HyperlinkLabel.callOnAction(action: (ActionEvent) -> Unit) =
        onAction(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_RangeSlider.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.RangeSlider
import kotlin.Double
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [RangeSlider] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.rangeSlider(
    min: Double = 0.0,
    max: Double = 1.0,
    lowValue: Double = 0.25,
    highValue: Double = 0.75
): RangeSlider = rangeSlider(min = min, max = max, lowValue = lowValue, highValue = highValue) { }

/**
 * Create a [RangeSlider] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun rangeSlider(
    min: Double = 0.0,
    max: Double = 1.0,
    lowValue: Double = 0.25,
    highValue: Double = 0.75,
    configuration: (@KtfxLayoutDslMarker RangeSlider).() -> Unit
): RangeSlider {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = RangeSlider(min, max, lowValue, highValue)
    child.configuration()
    return child
}

/**
 * Add a [RangeSlider] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.rangeSlider(
    min: Double = 0.0,
    max: Double = 1.0,
    lowValue: Double = 0.25,
    highValue: Double = 0.75,
    configuration: (@KtfxLayoutDslMarker RangeSlider).() -> Unit
): RangeSlider {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = RangeSlider(min, max, lowValue, highValue)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [RangeSlider].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledRangeSlider(
    min: Double = 0.0,
    max: Double = 1.0,
    lowValue: Double = 0.25,
    highValue: Double = 0.75,
    vararg styleClass: String,
    id: String? = null
): RangeSlider = styledRangeSlider(
    min = min, max = max, lowValue = lowValue, highValue = highValue,
    styleClass = *styleClass, id = id
) { }

/**
 * Add a styled [RangeSlider] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledRangeSlider(
    min: Double = 0.0,
    max: Double = 1.0,
    lowValue: Double = 0.25,
    highValue: Double = 0.75,
    vararg styleClass: String,
    id: String? = null
): RangeSlider = styledRangeSlider(
    min = min, max = max, lowValue = lowValue, highValue = highValue,
    styleClass = *styleClass, id = id
) { }

/**
 * Create a styled [RangeSlider] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledRangeSlider(
    min: Double = 0.0,
    max: Double = 1.0,
    lowValue: Double = 0.25,
    highValue: Double = 0.75,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker RangeSlider).() -> Unit
): RangeSlider {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = RangeSlider(min, max, lowValue, highValue)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [RangeSlider] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledRangeSlider(
    min: Double = 0.0,
    max: Double = 1.0,
    lowValue: Double = 0.25,
    highValue: Double = 0.75,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker RangeSlider).() -> Unit
): RangeSlider {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = RangeSlider(min, max, lowValue, highValue)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-layouts/src/com/jfoenix/controls/KtfxJFXClippedPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXClippedPane
import javafx.scene.Node
import ktfx.layouts.NodeManager
import kotlin.contracts.ExperimentalContracts

/**
 * [JFXClippedPane] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxJFXClippedPane : JFXClippedPane(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { children += it }
}


<|start_filename|>ktfx-commons/src/ktfx/print/PageRange.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.print

import javafx.print.PageRange

/**
 * Create a [PageRange] ranging from [this] to [endPage].
 * @see kotlin.ranges.until
 */
inline infix fun Int.untilPage(endPage: Int): PageRange = PageRange(this, endPage)


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/layouts/JFoenix.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.layouts

import com.hendraanggrian.kotlinpoet.asNullable
import com.hendraanggrian.kotlinpoet.dsl.ParameterSpecHandlerScope
import com.hendraanggrian.kotlinpoet.parameterizedBy
import com.hendraanggrian.kotlinpoet.typeVarBy
import com.hendraanggrian.kotlinpoet.typeVarOf
import com.jfoenix.controls.JFXBadge
import com.jfoenix.controls.JFXButton
import com.jfoenix.controls.JFXCheckBox
import com.jfoenix.controls.JFXChip
import com.jfoenix.controls.JFXChipView
import com.jfoenix.controls.JFXClippedPane
import com.jfoenix.controls.JFXColorPicker
import com.jfoenix.controls.JFXComboBox
import com.jfoenix.controls.JFXDatePicker
import com.jfoenix.controls.JFXDecorator
import com.jfoenix.controls.JFXDefaultChip
import com.jfoenix.controls.JFXDrawer
import com.jfoenix.controls.JFXDrawersStack
import com.jfoenix.controls.JFXHamburger
import com.jfoenix.controls.JFXListCell
import com.jfoenix.controls.JFXListView
import com.jfoenix.controls.JFXMasonryPane
import com.jfoenix.controls.JFXNodesList
import com.jfoenix.controls.JFXPasswordField
import com.jfoenix.controls.JFXProgressBar
import com.jfoenix.controls.JFXRadioButton
import com.jfoenix.controls.JFXRippler
import com.jfoenix.controls.JFXScrollPane
import com.jfoenix.controls.JFXSlider
import com.jfoenix.controls.JFXSpinner
import com.jfoenix.controls.JFXTabPane
import com.jfoenix.controls.JFXTextArea
import com.jfoenix.controls.JFXTextField
import com.jfoenix.controls.JFXTimePicker
import com.jfoenix.controls.JFXToggleButton
import com.jfoenix.controls.JFXToggleNode
import com.jfoenix.controls.JFXTogglePane
import com.jfoenix.controls.JFXToolbar
import com.jfoenix.controls.JFXTreeCell
import com.jfoenix.controls.JFXTreeTableView
import com.jfoenix.controls.JFXTreeView
import com.jfoenix.controls.JFXTreeViewPath
import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject
import com.squareup.kotlinpoet.asClassName
import com.hendraanggrian.ktfx.codegen.S
import com.hendraanggrian.ktfx.codegen.T
import javafx.scene.Node
import javafx.scene.control.TreeView
import javafx.stage.Stage
import java.time.LocalTime

val LayoutsFactory.Companion.JFoenix: LayoutsFactory
    get() = object : LayoutsFactory("thirdparty/jfoenix-layouts/src", "ktfx.jfoenix.layouts", "JFoenixLayoutsKt") {
        init {
            JFXBadge::class(customClass = true)
            JFXButton::class { text(); graphic() }
            JFXCheckBox::class { text() }
            JFXChip::class(T) { chipView(); item() }
            JFXChipView::class(T)
            JFXClippedPane::class(customClass = true)
            JFXColorPicker::class { color() }
            JFXComboBox::class(T) { items(T) }
            JFXDatePicker::class { date() }
            JFXDecorator::class {
                add<Stage>("stage")
                add<Node>("node")
                "fullScreen"<Boolean> { defaultValue("true") }
                "max"<Boolean> { defaultValue("true") }
                "min"<Boolean> { defaultValue("true") }
            }
            JFXDefaultChip::class(T) { chipView(); item() }
            JFXDrawer::class(customClass = true)
            JFXDrawersStack::class()
            JFXHamburger::class()
            JFXListCell::class(T)
            JFXListView::class(T)
            JFXMasonryPane::class(customClass = true)
            JFXNodesList::class(customClass = true)
            JFXPasswordField::class()
            JFXProgressBar::class { progress() }
            JFXRadioButton::class { text() }
            JFXRippler::class(customClass = true)
            JFXScrollPane::class(customClass = true)
            JFXSlider::class { slider("50.0") }
            JFXSpinner::class { progress() }
            JFXTabPane::class(customClass = true)
            JFXTextArea::class { text() }
            JFXTextField::class { text() }
            JFXTimePicker::class { "time"(LocalTime::class.asClassName().asNullable()) { defaultValue("null") } }
            JFXToggleButton::class()
            JFXToggleNode::class { graphic() }
            JFXTogglePane::class(customClass = true)
            JFXToolbar::class(customClass = true)
            JFXTreeCell::class(T)
            JFXTreeTableView::class("S".typeVarBy(RecursiveTreeObject::class.parameterizedBy(S))) {
                treeItem("root", S)
            }
            JFXTreeView::class(T) { treeItem("root", T) }
            JFXTreeViewPath::class {
                "treeView"(TreeView::class.asClassName().parameterizedBy("*".typeVarOf()).asNullable()) {
                    defaultValue("null")
                }
            }
        }

        fun ParameterSpecHandlerScope.chipView() = add("view", JFXChipView::class.asClassName().parameterizedBy(T))
        fun ParameterSpecHandlerScope.item() = add("item", T)
    }

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/media/MediaTest.kt<|end_filename|>
package ktfx.listeners

import com.hendraanggrian.ktfx.test.BaseMediaTest
import javafx.scene.media.Media
import kotlin.test.Ignore

@Ignore
class MediaTest : BaseMediaTest() {

    override fun Media.callOnError(action: () -> Unit) = onError(action)
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ButtonBarTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.control.ButtonBar
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.apache.commons.lang3.SystemUtils
import kotlin.test.Test
import kotlin.test.assertEquals

class ButtonBarTest : LayoutsTest<KtfxPane, ButtonBar>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = buttonBar { }
    override fun KtfxPane.child2() = buttonBar()
    override fun KtfxPane.child3() = buttonBar { }

    override fun ButtonBar.testDefaultValues() {
        assertEquals(
            when {
                SystemUtils.IS_OS_WINDOWS -> ButtonBar.BUTTON_ORDER_WINDOWS
                SystemUtils.IS_OS_MAC -> ButtonBar.BUTTON_ORDER_MAC_OS
                SystemUtils.IS_OS_LINUX -> ButtonBar.BUTTON_ORDER_LINUX
                else -> ButtonBar.BUTTON_ORDER_NONE
            }, buttonOrder
        )
    }

    @Test
    fun stringInvocation() {
        buttonBar {
            assertThat(buttons).isEmpty()
            button("Hello")
            "World" {
            }
            assertEquals(2, buttons.size)
        }
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/MenuBarTest.kt<|end_filename|>
package ktfx.layouts

import com.google.common.truth.Truth.assertThat
import javafx.scene.control.MenuBar
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.Test
import kotlin.test.assertEquals

class MenuBarTest : LayoutsTest<KtfxPane, MenuBar>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = menuBar { }
    override fun KtfxPane.child2() = menuBar()
    override fun KtfxPane.child3() = menuBar { }

    @Test
    fun stringInvocation() {
        menuBar {
            assertThat(menus).isEmpty()
            menu("Hello")
            "World" {
            }
            assertEquals(2, menus.size)
        }
    }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/BindingsInteger.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("BindingsKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.Observable
import javafx.beans.binding.Bindings
import javafx.beans.binding.IntegerBinding
import javafx.beans.value.ObservableBooleanValue
import javafx.beans.value.ObservableDoubleValue
import javafx.beans.value.ObservableFloatValue
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableLongValue
import javafx.beans.value.ObservableObjectValue
import javafx.collections.ObservableList
import javafx.collections.ObservableMap
import javafx.collections.ObservableSet
import ktfx.collections.observableListOf
import ktfx.collections.toObservableList
import java.util.concurrent.Callable

/** Create an [IntegerBinding] with multiple [Observable] dependencies. */
inline fun intBindingOf(vararg dependencies: Observable, noinline valueProvider: () -> Int): IntegerBinding =
    Bindings.createIntegerBinding(Callable(valueProvider), *dependencies)

/** Create a [IntegerBinding] with multiple [Observable] dependencies using collection. */
fun intBindingOf(dependencies: Collection<Observable>, valueProvider: () -> Int): IntegerBinding =
    intBindingOf(*dependencies.toTypedArray(), valueProvider = valueProvider)

/** Create an [IntegerBinding] with single [ObservableList] dependency. */
fun <E> ObservableList<E>.asInt(valueProvider: (List<E>) -> Int): IntegerBinding =
    object : IntegerBinding() {
        override fun dispose(): Unit = unbind(this@asInt)
        override fun computeValue(): Int = valueProvider(this@asInt)
        override fun getDependencies(): ObservableList<*> = this@asInt

        init {
            bind(this@asInt)
        }
    }

/** Create an [IntegerBinding] with single [ObservableSet] dependency. */
fun <E> ObservableSet<E>.asInt(valueProvider: (Set<E>) -> Int): IntegerBinding =
    object : IntegerBinding() {
        override fun dispose(): Unit = unbind(this@asInt)
        override fun computeValue(): Int = valueProvider(this@asInt)
        override fun getDependencies(): ObservableList<*> = this@asInt.toObservableList()

        init {
            bind(this@asInt)
        }
    }

/** Create an [IntegerBinding] with single [ObservableMap] dependency. */
fun <K, V> ObservableMap<K, V>.asInt(valueProvider: (Map<K, V>) -> Int): IntegerBinding =
    object : IntegerBinding() {
        override fun dispose(): Unit = unbind(this@asInt)
        override fun computeValue(): Int = valueProvider(this@asInt)
        override fun getDependencies(): ObservableList<*> = this@asInt.keys.toObservableList()

        init {
            bind(this@asInt)
        }
    }

/** Create an [IntegerBinding] with single [ObservableObjectValue] dependency. */
fun <V> ObservableObjectValue<V>.asInt(valueProvider: (V?) -> Int): IntegerBinding =
    object : IntegerBinding() {
        override fun dispose(): Unit = unbind(this@asInt)
        override fun computeValue(): Int = valueProvider(this@asInt.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asInt)

        init {
            bind(this@asInt)
        }
    }

/** Create an [IntegerBinding] with single [ObservableBooleanValue] dependency. */
fun ObservableBooleanValue.asInt(valueProvider: (Boolean) -> Int): IntegerBinding =
    object : IntegerBinding() {
        override fun dispose(): Unit = unbind(this@asInt)
        override fun computeValue(): Int = valueProvider(this@asInt.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asInt)

        init {
            bind(this@asInt)
        }
    }

/** Create an [IntegerBinding] with single [ObservableDoubleValue] dependency. */
fun ObservableDoubleValue.asInt(valueProvider: (Double) -> Int): IntegerBinding =
    object : IntegerBinding() {
        override fun dispose(): Unit = unbind(this@asInt)
        override fun computeValue(): Int = valueProvider(this@asInt.value as Double)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asInt)

        init {
            bind(this@asInt)
        }
    }

/** Create an [IntegerBinding] with single [ObservableFloatValue] dependency. */
fun ObservableFloatValue.asInt(valueProvider: (Float) -> Int): IntegerBinding =
    object : IntegerBinding() {
        override fun dispose(): Unit = unbind(this@asInt)
        override fun computeValue(): Int = valueProvider(this@asInt.value as Float)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asInt)

        init {
            bind(this@asInt)
        }
    }

/** Create an [IntegerBinding] with single [ObservableIntegerValue] dependency. */
fun ObservableIntegerValue.asInt(valueProvider: (Int) -> Int): IntegerBinding =
    object : IntegerBinding() {
        override fun dispose(): Unit = unbind(this@asInt)
        override fun computeValue(): Int = valueProvider(this@asInt.value as Int)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asInt)

        init {
            bind(this@asInt)
        }
    }

/** Create an [IntegerBinding] with single [ObservableLongValue] dependency. */
fun ObservableLongValue.asInt(valueProvider: (Long) -> Int): IntegerBinding =
    object : IntegerBinding() {
        override fun dispose(): Unit = unbind(this@asInt)
        override fun computeValue(): Int = valueProvider(this@asInt.value as Long)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asInt)

        init {
            bind(this@asInt)
        }
    }


<|start_filename|>ktfx-commons/src/ktfx/bindings/BindingsBoolean.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("BindingsKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.Observable
import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding
import javafx.beans.value.ObservableBooleanValue
import javafx.beans.value.ObservableDoubleValue
import javafx.beans.value.ObservableFloatValue
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableLongValue
import javafx.beans.value.ObservableObjectValue
import javafx.collections.ObservableList
import javafx.collections.ObservableMap
import javafx.collections.ObservableSet
import ktfx.collections.observableListOf
import ktfx.collections.toObservableList
import java.util.concurrent.Callable

/** Create a [BooleanBinding] with multiple [Observable] dependencies. */
inline fun booleanBindingOf(vararg dependencies: Observable, noinline valueProvider: () -> Boolean): BooleanBinding =
    Bindings.createBooleanBinding(Callable(valueProvider), *dependencies)

/** Create a [BooleanBinding] with multiple [Observable] dependencies using collection. */
fun booleanBindingOf(dependencies: Collection<Observable>, valueProvider: () -> Boolean): BooleanBinding =
    booleanBindingOf(*dependencies.toTypedArray(), valueProvider = valueProvider)

/** Create an [BooleanBinding] with single [ObservableList] dependency. */
fun <E> ObservableList<E>.asBoolean(valueProvider: (List<E>) -> Boolean): BooleanBinding =
    object : BooleanBinding() {
        override fun dispose(): Unit = unbind(this@asBoolean)
        override fun computeValue(): Boolean = valueProvider(this@asBoolean)
        override fun getDependencies(): ObservableList<*> = this@asBoolean

        init {
            bind(this@asBoolean)
        }
    }

/** Create an [BooleanBinding] with single [ObservableSet] dependency. */
fun <E> ObservableSet<E>.asBoolean(valueProvider: (Set<E>) -> Boolean): BooleanBinding =
    object : BooleanBinding() {
        override fun dispose(): Unit = unbind(this@asBoolean)
        override fun computeValue(): Boolean = valueProvider(this@asBoolean)
        override fun getDependencies(): ObservableList<*> = this@asBoolean.toObservableList()

        init {
            bind(this@asBoolean)
        }
    }

/** Create an [BooleanBinding] with single [ObservableMap] dependency. */
fun <K, V> ObservableMap<K, V>.asBoolean(valueProvider: (Map<K, V>) -> Boolean): BooleanBinding =
    object : BooleanBinding() {
        override fun dispose(): Unit = unbind(this@asBoolean)
        override fun computeValue(): Boolean = valueProvider(this@asBoolean)
        override fun getDependencies(): ObservableList<*> = this@asBoolean.keys.toObservableList()

        init {
            bind(this@asBoolean)
        }
    }

/** Create a [BooleanBinding] with single [ObservableObjectValue] dependency. */
fun <V> ObservableObjectValue<V>.asBoolean(valueProvider: (V?) -> Boolean): BooleanBinding =
    object : BooleanBinding() {
        override fun dispose(): Unit = unbind(this@asBoolean)
        override fun computeValue(): Boolean = valueProvider(this@asBoolean.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asBoolean)

        init {
            bind(this@asBoolean)
        }
    }

/** Create a [BooleanBinding] with single [ObservableBooleanValue] dependency. */
fun ObservableBooleanValue.asBoolean(valueProvider: (Boolean) -> Boolean): BooleanBinding =
    object : BooleanBinding() {
        override fun dispose(): Unit = unbind(this@asBoolean)
        override fun computeValue(): Boolean = valueProvider(this@asBoolean.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asBoolean)

        init {
            bind(this@asBoolean)
        }
    }

/** Create a [BooleanBinding] with single [ObservableDoubleValue] dependency. */
fun ObservableDoubleValue.asBoolean(valueProvider: (Double) -> Boolean): BooleanBinding =
    object : BooleanBinding() {
        override fun dispose(): Unit = unbind(this@asBoolean)
        override fun computeValue(): Boolean = valueProvider(this@asBoolean.value as Double)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asBoolean)

        init {
            bind(this@asBoolean)
        }
    }

/** Create a [BooleanBinding] with single [ObservableFloatValue] dependency. */
fun ObservableFloatValue.asBoolean(valueProvider: (Float) -> Boolean): BooleanBinding =
    object : BooleanBinding() {
        override fun dispose(): Unit = unbind(this@asBoolean)
        override fun computeValue(): Boolean = valueProvider(this@asBoolean.value as Float)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asBoolean)

        init {
            bind(this@asBoolean)
        }
    }

/** Create a [BooleanBinding] with single [ObservableIntegerValue] dependency. */
fun ObservableIntegerValue.asBoolean(valueProvider: (Int) -> Boolean): BooleanBinding =
    object : BooleanBinding() {
        override fun dispose(): Unit = unbind(this@asBoolean)
        override fun computeValue(): Boolean = valueProvider(this@asBoolean.value as Int)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asBoolean)

        init {
            bind(this@asBoolean)
        }
    }

/** Create a [BooleanBinding] with single [ObservableLongValue] dependency. */
fun ObservableLongValue.asBoolean(valueProvider: (Long) -> Boolean): BooleanBinding =
    object : BooleanBinding() {
        override fun dispose(): Unit = unbind(this@asBoolean)
        override fun computeValue(): Boolean = valueProvider(this@asBoolean.value as Long)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asBoolean)

        init {
            bind(this@asBoolean)
        }
    }


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_Transform.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.transform.Transform
import javafx.scene.transform.TransformChangedEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Transform.setOnTransformChanged
 */
public fun Transform.onTransformChanged(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(TransformChangedEvent) -> Unit
) {
    return setOnTransformChanged { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/dialogs/CommandLinksDialogsTest.kt<|end_filename|>
package ktfx.controlsfx.dialogs

import com.hendraanggrian.ktfx.test.DialogShowingTest
import org.controlsfx.dialog.CommandLinksDialog
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class CommandLinksDialogsTest : DialogShowingTest() {

    @Test
    fun commandLinksDialogFromArray() {
        interact {
            assertEquals(
                "Yes",
                commandLinksDialog(
                    "Command links dialog", sampleGraphic,
                    CommandLinksDialog.CommandLinksButtonType("Yes", true)
                ) {
                    closeOnShow(this)
                    assertEquals("Command links dialog", headerText)
                    assertEquals(sampleGraphic, graphic)
                }.get().text
            )
            assertEquals("Yes", commandLinksDialog(CommandLinksDialog.CommandLinksButtonType("Yes", true)) {
                closeOnShow(this)
            }.get().text)
        }
    }

    @Test
    fun commandLinksDialogFromList() {
        interact {
            assertEquals(
                "Yes",
                commandLinksDialog(
                    "Command links dialog", sampleGraphic,
                    listOf(CommandLinksDialog.CommandLinksButtonType("Yes", true))
                ) {
                    closeOnShow(this)
                    assertEquals("Command links dialog", headerText)
                    assertEquals(sampleGraphic, graphic)
                }.get().text
            )
            assertEquals("Yes", commandLinksDialog(listOf(CommandLinksDialog.CommandLinksButtonType("Yes", true))) {
                closeOnShow(this)
            }.get().text)
        }
    }
}

<|start_filename|>ktfx-listeners/src/javafx/scene/Node.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("FxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.event.Event
import javafx.event.EventHandler
import javafx.event.EventType
import javafx.scene.Node
import javafx.scene.SnapshotParameters
import javafx.scene.SnapshotResult
import javafx.scene.image.WritableImage

/** Registers an event filter to this node. */
inline fun <E : Event> Node.eventFilter(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventFilter(type, it) }

/** Registers an event handler to this node. */
inline fun <E : Event> Node.eventHandler(
    type: EventType<E>,
    noinline action: (E) -> Unit
): EventHandler<E> = EventHandler(action)
    .also { addEventHandler(type, it) }

/** Takes a snapshot of this node at the next frame and calls the specified callback method when the image is ready. */
inline fun Node.capture(
    image: WritableImage? = null,
    configuration: SnapshotParameters.() -> Unit = { },
    noinline callback: (SnapshotResult) -> Unit
): Unit = snapshot({ callback(it); null }, SnapshotParameters().apply(configuration), image)


<|start_filename|>ktfx-layouts/src/KtfxManagers.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.Node
import javafx.scene.control.Menu
import javafx.scene.control.MenuItem
import javafx.scene.control.Tab
import javafx.scene.control.TitledPane
import javafx.scene.control.ToggleButton
import javafx.scene.shape.PathElement

/**
 * A manager contains a set of children.
 * @param T type of the child.
 */
interface KtfxManager<T> {

    /**
     * Allows child to be added dynamically with Kotlin DSL in the context of this manager.
     * @param child child to add
     * @return the child added
     */
    fun <C : T> addChild(child: C): C
}

/**
 * Container of [MenuItem].
 * @see javafx.scene.control.ContextMenu
 * @see javafx.scene.control.Menu
 * @see javafx.scene.control.MenuButton
 * @see javafx.scene.control.SplitMenuButton
 */
interface MenuItemManager : KtfxManager<MenuItem>

/**
 * Container of [Menu].
 * @see javafx.scene.control.MenuBar
 */
interface MenuManager : KtfxManager<Menu>

/** Container of [Node], being used in most subclasses of [javafx.scene.Parent]. */
interface NodeManager : KtfxManager<Node>

/**
 * Container of [PathElement].
 * @see javafx.scene.shape.Path
 */
interface PathElementManager : KtfxManager<PathElement>

/**
 * Container of [Tab].
 * Also being used in `JFXTabPane.kt`.
 * @see javafx.scene.control.TabPane
 */
interface TabManager : KtfxManager<Tab>

/**
 * Container of [TitledPane].
 * @see javafx.scene.control.Accordion
 */
interface TitledPaneManager : KtfxManager<TitledPane>

/**
 * Container of [ToggleButton].
 * Used for `SegmentedButton.kt`.
 */
interface ToggleButtonManager : KtfxManager<ToggleButton>


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/TabTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.Tab
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class TabTest : LayoutsTest<KtfxTabPane, Tab>() {

    override fun manager() = KtfxTabPane()
    override fun KtfxTabPane.childCount() = tabs.size
    override fun child1() = tab { }
    override fun KtfxTabPane.child2() = tab()
    override fun KtfxTabPane.child3() = tab { }

    override fun Tab.testDefaultValues() {
        assertNull(text)
        assertNull(graphic)
    }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_PasswordField.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.PasswordField
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [PasswordField] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.passwordField(): PasswordField = passwordField() { }

/**
 * Create a [PasswordField] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun passwordField(configuration: (@KtfxLayoutDslMarker PasswordField).() -> Unit):
    PasswordField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PasswordField()
    child.configuration()
    return child
}

/**
 * Add a [PasswordField] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.passwordField(
    configuration: (
        @KtfxLayoutDslMarker
        PasswordField
    ).() -> Unit
): PasswordField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PasswordField()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [PasswordField].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledPasswordField(vararg styleClass: String, id: String? = null): PasswordField =
    styledPasswordField(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [PasswordField] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledPasswordField(vararg styleClass: String, id: String? = null):
    PasswordField = styledPasswordField(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [PasswordField] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledPasswordField(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker PasswordField).() -> Unit
): PasswordField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PasswordField()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [PasswordField] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledPasswordField(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker PasswordField).() -> Unit
): PasswordField {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PasswordField()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>rulesets/basic/tests/src/com/hendraanggrian/ktfx/rules/ExpressionFunctionReturnTypeRuleTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.rules

import com.hendraanggrian.ktfx.test.RuleTest
import kotlin.test.Test

class ExpressionFunctionReturnTypeRuleTest : RuleTest {
    override val rule = ExpressionFunctionReturnTypeRule()

    @Test
    fun function() = assertRule(
        lintErrorOf(2, 1, "Expression function need return type")
    ) {
        """
            fun function() { }
            fun expressionFunction() = "Hello world"
        """
    }

    /*@Test*/ fun property() = assertRule(
        lintErrorOf(1, 1, "Property need return type"),
        lintErrorOf(2, 1, "Property need return type")
    ) {
        """
            var property = "Hello"
            var propertyAccessor get() = "World"
        """
    }
}

<|start_filename|>ktfx-coroutines/tests/src/javafx/scene/control/TreeTableViewTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.TreeTableColumn
import javafx.scene.control.TreeTableView
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseTreeTableViewTest

class TreeTableViewTest : BaseTreeTableViewTest() {

    override fun <S> TreeTableView<S>.callOnSort(action: (SortEvent<TreeTableView<S>>) -> Unit) =
        onSort(Dispatchers.Unconfined) { action(it) }

    override fun <S> TreeTableView<S>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit) =
        onScrollTo(Dispatchers.Unconfined) { action(it) }

    override fun <S> TreeTableView<S>.callOnScrollToColumn(action: (ScrollToEvent<TreeTableColumn<S, *>>) -> Unit) =
        onScrollToColumn(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/ClosePathTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.ClosePath
import com.hendraanggrian.ktfx.test.LayoutsTest

class ClosePathTest : LayoutsTest<KtfxPath, ClosePath>() {

    override fun manager() = KtfxPath()
    override fun KtfxPath.childCount() = elements.size
    override fun child1() = closePath { }
    override fun KtfxPath.child2() = closePath()
    override fun KtfxPath.child3() = closePath { }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXTreeViewTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTreeView
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class JFXTreeViewTest : LayoutsTest<KtfxPane, JFXTreeView<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxTreeView<String> { }
    override fun KtfxPane.child2() = jfxTreeView<String>()
    override fun KtfxPane.child3() = jfxTreeView<String> { }

    override fun JFXTreeView<String>.testDefaultValues() {
        assertNull(root)
    }
}

<|start_filename|>thirdparty/controlsfx-commons/tests/src/ktfx/controlsfx/controls/BordersTest.kt<|end_filename|>
package ktfx.controlsfx.controls

import com.hendraanggrian.ktfx.test.initToolkit
import javafx.scene.control.Label
import javafx.scene.layout.Region
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class BordersTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun emptyBorder() {
        val label = Label()
        assertNull(label.border)

        val wrappedLabel = Label().wrapBorders { empty { padding(1.0, 2.0, 3.0, 4.0) } } as Region
        assertEquals(1, wrappedLabel.border.strokes.size)

        val stroke = wrappedLabel.border.strokes.first()
        assertEquals(1.0, stroke.widths.top)
        assertEquals(2.0, stroke.widths.right)
        assertEquals(3.0, stroke.widths.bottom)
        assertEquals(4.0, stroke.widths.left)
    }

    @Test
    fun etchedBorder() {
        val label = Label()
        assertNull(label.border)

        val wrappedLabel = Label().wrapBorders { etched { title = "Hello world" } } as Region
        assertEquals(1, wrappedLabel.border.strokes.size)
    }

    @Test
    fun lineBorder() {
        val label = Label()
        assertNull(label.border)

        val wrappedLabel = Label().wrapBorders { line { title = "Hello world" } } as Region
        assertEquals(1, wrappedLabel.border.strokes.size)
    }
}

<|start_filename|>ktfx-listeners/src/ktfx/listeners/_MediaPlayer.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.media.MediaMarkerEvent
import javafx.scene.media.MediaPlayer
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see MediaPlayer.setOnError
 */
public inline fun MediaPlayer.onError(noinline action: () -> Unit) {
    return setOnError(action)
}

/**
 * @see MediaPlayer.setOnMarker
 */
public inline fun MediaPlayer.onMarker(noinline action: (MediaMarkerEvent) -> Unit) {
    return setOnMarker(action)
}

/**
 * @see MediaPlayer.setOnEndOfMedia
 */
public inline fun MediaPlayer.onEndOfMedia(noinline action: () -> Unit) {
    return setOnEndOfMedia(action)
}

/**
 * @see MediaPlayer.setOnReady
 */
public inline fun MediaPlayer.onReady(noinline action: () -> Unit) {
    return setOnReady(action)
}

/**
 * @see MediaPlayer.setOnPlaying
 */
public inline fun MediaPlayer.onPlaying(noinline action: () -> Unit) {
    return setOnPlaying(action)
}

/**
 * @see MediaPlayer.setOnPaused
 */
public inline fun MediaPlayer.onPaused(noinline action: () -> Unit) {
    return setOnPaused(action)
}

/**
 * @see MediaPlayer.setOnStopped
 */
public inline fun MediaPlayer.onStopped(noinline action: () -> Unit) {
    return setOnStopped(action)
}

/**
 * @see MediaPlayer.setOnHalted
 */
public inline fun MediaPlayer.onHalted(noinline action: () -> Unit) {
    return setOnHalted(action)
}

/**
 * @see MediaPlayer.setOnRepeat
 */
public inline fun MediaPlayer.onRepeat(noinline action: () -> Unit) {
    return setOnRepeat(action)
}

/**
 * @see MediaPlayer.setOnStalled
 */
public inline fun MediaPlayer.onStalled(noinline action: () -> Unit) {
    return setOnStalled(action)
}


<|start_filename|>ktfx-commons/src/ktfx/collections/ObservableCollectionsList.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ObservableCollectionsKt")
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.collections

import javafx.collections.FXCollections
import javafx.collections.ObservableList
import java.util.Comparator
import java.util.Random
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
 * Returns an empty read-only [ObservableList].
 * @see emptyList
 */
inline fun <T> emptyObservableList(): ObservableList<T> = FXCollections.emptyObservableList()

/**
 * Returns a new read-only [ObservableList] of given elements.
 * @see listOf
 */
fun <T> observableListOf(vararg elements: T): ObservableList<T> =
    if (elements.isNotEmpty()) FXCollections.unmodifiableObservableList(elements.toMutableObservableList())
    else emptyObservableList()

/**
 * Returns an empty read-only [ObservableList] of one element.
 * @see listOf
 */
inline fun <T> observableListOf(element: T): ObservableList<T> = FXCollections.singletonObservableList(element)

/**
 * Returns an empty read-only [ObservableList].
 * @see listOf
 */
inline fun <T> observableListOf(): ObservableList<T> = emptyObservableList()

/**
 * Returns an empty [ObservableList].
 * @see mutableListOf
 */
inline fun <T> mutableObservableListOf(): ObservableList<T> = FXCollections.observableArrayList()

/**
 * Returns a new [ObservableList] with the given elements.
 * @see mutableListOf
 */
fun <T> mutableObservableListOf(vararg elements: T): ObservableList<T> =
    if (elements.isEmpty()) mutableObservableListOf() else FXCollections.observableArrayList(*elements)

/**
 * Returns a new read-only [ObservableList] either of single given element, if it is not null,
 * or empty list if the element is null.
 * @see listOfNotNull
 */
fun <T : Any> observableListOfNotNull(element: T?): ObservableList<T> =
    if (element != null) observableListOf(element) else emptyObservableList()

/**
 * Returns a new read-only [ObservableList] only of those given elements, that are not null.
 * @see listOfNotNull
 */
fun <T : Any> observableListOfNotNull(vararg elements: T?): ObservableList<T> =
    elements.filterNotNullTo(mutableObservableListOf())

/**
 * Builds a new read-only [ObservableList] by populating a [MutableList]
 * using the given [builderAction] and returning a read-only list with the same elements.
 * @see buildList
 */
@ExperimentalStdlibApi
inline fun <T> buildObservableList(builderAction: MutableList<T>.() -> Unit): List<T> {
    contract { callsInPlace(builderAction, InvocationKind.EXACTLY_ONCE) }
    return buildList(builderAction).toObservableList()
}

/**
 * Returns an [ObservableList] containing all elements.
 * @see Array.toList
 */
fun <T> Array<out T>.toObservableList(): ObservableList<T> = when (size) {
    0 -> emptyObservableList()
    1 -> observableListOf(this[0])
    else -> FXCollections.unmodifiableObservableList(this.toMutableObservableList())
}

/**
 * Returns a new [ObservableList] filled with all elements of this array.
 * @see Array.toMutableList
 */
inline fun <T> Array<out T>.toMutableObservableList(): ObservableList<T> = FXCollections.observableArrayList(*this)

/**
 * Returns an [ObservableList] containing all elements.
 * @see Iterable.toList
 */
fun <T> Iterable<T>.toObservableList(): ObservableList<T> {
    if (this is Collection) {
        return when (size) {
            0 -> emptyObservableList()
            1 -> observableListOf(if (this is List) get(0) else iterator().next())
            else -> FXCollections.unmodifiableObservableList(this.toMutableObservableList())
        }
    }
    return this.toMutableObservableList().optimizeReadOnlyList()
}

/**
 * Returns a new [ObservableList] filled with all elements of this collection.
 * @see Iterable.toMutableList
 */
fun <T> Iterable<T>.toMutableObservableList(): ObservableList<T> {
    if (this is Collection)
        return this.toMutableObservableList()
    return toCollection(FXCollections.observableArrayList())
}

/**
 * Returns a new [ObservableList] filled with all elements of this collection.
 * @see Collection.toMutableList
 */
inline fun <T> Collection<T>.toMutableObservableList(): ObservableList<T> = FXCollections.observableArrayList(this)

/**
 * Returns a [ObservableList] containing all elements.
 * @see Sequence.toList
 */
fun <T> Sequence<T>.toObservableList(): ObservableList<T> = toMutableObservableList().optimizeReadOnlyList()

/**
 * Returns a new [ObservableList] filled with all elements of this sequence.
 * @see Sequence.toMutableList
 */
fun <T> Sequence<T>.toMutableObservableList(): ObservableList<T> = toCollection(FXCollections.observableArrayList())

/** Copies elements from src to list, firing change notification once. */
inline fun <T> ObservableList<T>.copyTo(src: List<T>): Unit = FXCollections.copy(this, src)

/** Fills the list with obj, firing change notification once. */
inline fun <T> ObservableList<T>.fillTo(obj: T): Unit = FXCollections.fill(this, obj)

/** Replace all oldVal elements in the list with newVal element, firing change notification once. */
inline fun <T> ObservableList<T>.replaceAll(oldVal: T, newVal: T): Boolean =
    FXCollections.replaceAll(this, oldVal, newVal)

/** Reverse the order in the list, firing change notification once. */
inline fun ObservableList<*>.reverse(): Unit = FXCollections.reverse(this)

/** Rotates the list by distance, firing change notification once. */
inline fun ObservableList<*>.rotate(distance: Int): Unit = FXCollections.rotate(this, distance)

/** Shuffles all elements in the observable list, firing change notification once. */
inline fun ObservableList<*>.shuffle(rnd: Random? = null): Unit = FXCollections.shuffle(this, rnd)

/** Sorts the provided observable list, firing change notification once. */
inline fun <T : Comparable<T>> ObservableList<T>.sort(): Unit = FXCollections.sort(this)

/** Sorts the provided observable list using the c comparator, firing change notification once. */
inline infix fun <T> ObservableList<T>.sort(c: Comparator<T>): Unit = FXCollections.sort(this, c)


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/layout/AnchorPaneTest.kt<|end_filename|>
package ktfx.layouts

import com.hendraanggrian.ktfx.test.LayoutsTest
import javafx.scene.layout.AnchorPane
import kotlin.test.Test
import kotlin.test.assertEquals

class AnchorPaneTest : LayoutsTest<KtfxPane, AnchorPane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = anchorPane { }
    override fun KtfxPane.child2() = anchorPane()
    override fun KtfxPane.child3() = anchorPane { }

    @Test
    fun anchors() {
        anchorPane {
            val region1 = region().anchor(5)
            assertEquals(5.0, region1.topAnchor)
            assertEquals(5.0, region1.leftAnchor)
            assertEquals(5.0, region1.bottomAnchor)
            assertEquals(5.0, region1.rightAnchor)
            val region2 = region().anchor(top = 10, left = 20, bottom = 30, right = 40)
            assertEquals(10.0, region2.topAnchor)
            assertEquals(20.0, region2.leftAnchor)
            assertEquals(30.0, region2.bottomAnchor)
            assertEquals(40.0, region2.rightAnchor)
            val region3 = region().anchor(vertical = 10, horizontal = 20)
            assertEquals(10.0, region3.topAnchor)
            assertEquals(20.0, region3.leftAnchor)
            assertEquals(10.0, region3.bottomAnchor)
            assertEquals(20.0, region3.rightAnchor)

            region1.clearConstraints()
            assertEquals(region1.topAnchor, null)
            assertEquals(region1.leftAnchor, null)
            assertEquals(region1.bottomAnchor, null)
            assertEquals(region1.rightAnchor, null)

            region2.clearConstraints()
            assertEquals(region2.topAnchor, null)
            assertEquals(region2.leftAnchor, null)
            assertEquals(region2.bottomAnchor, null)
            assertEquals(region2.rightAnchor, null)

            region3.clearConstraints()
            assertEquals(region3.topAnchor, null)
            assertEquals(region3.leftAnchor, null)
            assertEquals(region3.bottomAnchor, null)
            assertEquals(region3.rightAnchor, null)

            assertEquals(children.size, 3)
        }
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/ToggleSwitchTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.ToggleSwitch
import kotlin.test.assertNull

class ToggleSwitchTest : LayoutsTest<KtfxPane, ToggleSwitch>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = toggleSwitch { }
    override fun KtfxPane.child2() = toggleSwitch()
    override fun KtfxPane.child3() = toggleSwitch { }

    override fun ToggleSwitch.testDefaultValues() {
        assertNull(text)
    }
}

<|start_filename|>website/build.gradle.kts<|end_filename|>
plugins {
    `git-publish`
}

gitPublish {
    repoUri.set("<EMAIL>:hendraanggrian/$RELEASE_ARTIFACT.git")
    branch.set("gh-pages")
    contents.from(
        "src",
        *ktfxArtifacts
            .map { "../$it/build/dokka" }
            .toTypedArray()
    )
}

tasks {
    register("clean") {
        delete(buildDir)
    }
    gitPublishCopy {
        dependsOn(
            *ktfxArtifacts
                .map { it.replace('/', ':') }
                .map { ":$it:dokkaHtml" }
                .toTypedArray()
        )
    }
}

val ktfxArtifacts: List<String>
    get() = listOf("commons", "layouts", "listeners", "coroutines").map { "$RELEASE_ARTIFACT-$it" } +
            listOf("controlsfx", "jfoenix").flatMap {
                listOf(
                    "thirdparty/$it-commons",
                    "thirdparty/$it-layouts",
                    "thirdparty/$it-listeners",
                    "thirdparty/$it-coroutines"
                )
            }

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_TaskProgressView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import javafx.concurrent.Task
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.TaskProgressView
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [TaskProgressView] to this manager.
 *
 * @return the control added.
 */
public fun <T : Task<*>> NodeManager.taskProgressView(): TaskProgressView<T> = taskProgressView() {
}

/**
 * Create a [TaskProgressView] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun <T : Task<*>> taskProgressView(
    configuration: (
        @KtfxLayoutDslMarker
        TaskProgressView<T>
    ).() -> Unit
): TaskProgressView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TaskProgressView<T>()
    child.configuration()
    return child
}

/**
 * Add a [TaskProgressView] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun <T : Task<*>> NodeManager.taskProgressView(
    configuration: (
        @KtfxLayoutDslMarker
        TaskProgressView<T>
    ).() -> Unit
): TaskProgressView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TaskProgressView<T>()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [TaskProgressView].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun <T : Task<*>> styledTaskProgressView(vararg styleClass: String, id: String? = null):
    TaskProgressView<T> = styledTaskProgressView(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [TaskProgressView] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun <T : Task<*>> NodeManager.styledTaskProgressView(
    vararg styleClass: String,
    id: String? =    
        null
): TaskProgressView<T> = styledTaskProgressView(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [TaskProgressView] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun <T : Task<*>> styledTaskProgressView(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker TaskProgressView<T>).() -> Unit
): TaskProgressView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TaskProgressView<T>()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [TaskProgressView] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun <T : Task<*>> NodeManager.styledTaskProgressView(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker TaskProgressView<T>).() -> Unit
): TaskProgressView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = TaskProgressView<T>()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/controlsfx-layouts/src/org/controlsfx/control/KtfxSegmentedButton.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import javafx.scene.Node
import javafx.scene.control.ToggleButton
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.ToggleButtonManager
import ktfx.layouts.toggleButton
import org.controlsfx.control.SegmentedButton
import kotlin.contracts.ExperimentalContracts

/**
 * [SegmentedButton] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxSegmentedButton : SegmentedButton(), ToggleButtonManager {

    final override fun <C : ToggleButton> addChild(child: C): C = child.also { buttons += it }

    /** Call [ToggleButtonManager.toggleButton] by string invocation. */
    inline operator fun String.invoke(
        graphic: Node? = null,
        configuration: (@KtfxLayoutDslMarker ToggleButton).() -> Unit
    ): ToggleButton = toggleButton(this, graphic, configuration)
}


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_ComboBoxBase.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.event.ActionEvent
import javafx.event.Event
import javafx.scene.control.ComboBoxBase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see ComboBoxBase.setOnAction
 */
public fun ComboBoxBase<*>.onAction(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ActionEvent) -> Unit
) {
    return setOnAction { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ComboBoxBase.setOnShowing
 */
public fun ComboBoxBase<*>.onShowing(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnShowing { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ComboBoxBase.setOnShown
 */
public fun ComboBoxBase<*>.onShown(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnShown { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ComboBoxBase.setOnHiding
 */
public fun ComboBoxBase<*>.onHiding(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnHiding { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see ComboBoxBase.setOnHidden
 */
public fun ComboBoxBase<*>.onHidden(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnHidden { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/stage/PopupWindowTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.event.Event
import javafx.stage.BasePopupWindowTest
import javafx.stage.PopupWindow
import kotlinx.coroutines.Dispatchers

class PopupWindowTest : BasePopupWindowTest() {

    override fun PopupWindow.callOnAutoHide(action: (Event) -> Unit) =
        onAutoHide(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/inputs/ClipboardTest.kt<|end_filename|>
package ktfx.inputs

import com.hendraanggrian.ktfx.test.JavaFXThreadRule
import javafx.scene.input.Clipboard
import javafx.scene.input.DataFormat
import org.junit.Rule
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class ClipboardTest {
    @Rule @JvmField var rule = JavaFXThreadRule()
    private lateinit var clipboard: Clipboard

    @BeforeTest
    fun start() {
        clipboard = Clipboard.getSystemClipboard()
    }

    @Test
    fun test() {
        clipboard[DataFormat.PLAIN_TEXT] = "Hello world"
        assertTrue(DataFormat.PLAIN_TEXT in clipboard)
        assertEquals("Hello world", clipboard[DataFormat.PLAIN_TEXT])
    }
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/SegmentedButtonTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import ktfx.layouts.toggleButton
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.SegmentedButton
import kotlin.test.Test
import kotlin.test.assertEquals

class SegmentedButtonTest : LayoutsTest<KtfxPane, SegmentedButton>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = segmentedButton { }
    override fun KtfxPane.child2() = segmentedButton()
    override fun KtfxPane.child3() = segmentedButton { }

    @Test
    fun stringInvocation() {
        segmentedButton {
            toggleButton("Hello")
            "World" {
            }
            assertEquals(2, buttons.size)
        }
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/TaskProgressViewTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import javafx.concurrent.Task
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.TaskProgressView

class TaskProgressViewTest : LayoutsTest<KtfxPane, TaskProgressView<Task<String>>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = taskProgressView<Task<String>> { }
    override fun KtfxPane.child2() = taskProgressView<Task<String>>()
    override fun KtfxPane.child3() = taskProgressView<Task<String>> { }
}

<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_Scene.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.Scene
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Scene.setOnMouseClicked
 */
public fun Scene.onMouseClicked(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseClicked { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnMouseDragged
 */
public fun Scene.onMouseDragged(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseDragged { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnMouseEntered
 */
public fun Scene.onMouseEntered(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseEntered { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnMouseExited
 */
public fun Scene.onMouseExited(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseExited { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnMouseMoved
 */
public fun Scene.onMouseMoved(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseMoved { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnMousePressed
 */
public fun Scene.onMousePressed(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMousePressed { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnMouseReleased
 */
public fun Scene.onMouseReleased(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnMouseReleased { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnDragDetected
 */
public fun Scene.onDragDetected(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseEvent) -> Unit
) {
    return setOnDragDetected { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnMouseDragOver
 */
public fun Scene.onMouseDragOver(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseDragEvent) -> Unit
) {
    return setOnMouseDragOver { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnMouseDragReleased
 */
public fun Scene.onMouseDragReleased(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseDragEvent) -> Unit
) {
    return setOnMouseDragReleased { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnMouseDragEntered
 */
public fun Scene.onMouseDragEntered(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseDragEvent) -> Unit
) {
    return setOnMouseDragEntered { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnMouseDragExited
 */
public fun Scene.onMouseDragExited(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(MouseDragEvent) -> Unit
) {
    return setOnMouseDragExited { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnScrollStarted
 */
public fun Scene.onScrollStarted(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ScrollEvent) -> Unit
) {
    return setOnScrollStarted { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnScroll
 */
public fun Scene.onScroll(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ScrollEvent) -> Unit
) {
    return setOnScroll { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnScrollFinished
 */
public fun Scene.onScrollFinished(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ScrollEvent) -> Unit
) {
    return setOnScrollFinished { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnRotationStarted
 */
public fun Scene.onRotationStarted(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(RotateEvent) -> Unit
) {
    return setOnRotationStarted { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnRotate
 */
public fun Scene.onRotate(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(RotateEvent) -> Unit
) {
    return setOnRotate { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnRotationFinished
 */
public fun Scene.onRotationFinished(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(RotateEvent) -> Unit
) {
    return setOnRotationFinished { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnZoomStarted
 */
public fun Scene.onZoomStarted(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ZoomEvent) -> Unit
) {
    return setOnZoomStarted { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnZoom
 */
public fun Scene.onZoom(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ZoomEvent) -> Unit
) {
    return setOnZoom { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnZoomFinished
 */
public fun Scene.onZoomFinished(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(ZoomEvent) -> Unit
) {
    return setOnZoomFinished { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnSwipeUp
 */
public fun Scene.onSwipeUp(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(SwipeEvent) -> Unit
) {
    return setOnSwipeUp { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnSwipeDown
 */
public fun Scene.onSwipeDown(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(SwipeEvent) -> Unit
) {
    return setOnSwipeDown { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnSwipeLeft
 */
public fun Scene.onSwipeLeft(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(SwipeEvent) -> Unit
) {
    return setOnSwipeLeft { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnSwipeRight
 */
public fun Scene.onSwipeRight(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(SwipeEvent) -> Unit
) {
    return setOnSwipeRight { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnTouchPressed
 */
public fun Scene.onTouchPressed(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(TouchEvent) -> Unit
) {
    return setOnTouchPressed { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnTouchMoved
 */
public fun Scene.onTouchMoved(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(TouchEvent) -> Unit
) {
    return setOnTouchMoved { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnTouchReleased
 */
public fun Scene.onTouchReleased(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(TouchEvent) -> Unit
) {
    return setOnTouchReleased { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnTouchStationary
 */
public fun Scene.onTouchStationary(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(TouchEvent) -> Unit
) {
    return setOnTouchStationary { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnDragEntered
 */
public fun Scene.onDragEntered(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DragEvent) -> Unit
) {
    return setOnDragEntered { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnDragExited
 */
public fun Scene.onDragExited(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DragEvent) -> Unit
) {
    return setOnDragExited { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnDragOver
 */
public fun Scene.onDragOver(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DragEvent) -> Unit
) {
    return setOnDragOver { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnDragDropped
 */
public fun Scene.onDragDropped(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DragEvent) -> Unit
) {
    return setOnDragDropped { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnDragDone
 */
public fun Scene.onDragDone(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(DragEvent) -> Unit
) {
    return setOnDragDone { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnKeyPressed
 */
public fun Scene.onKeyPressed(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(KeyEvent) -> Unit
) {
    return setOnKeyPressed { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnKeyReleased
 */
public fun Scene.onKeyReleased(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(KeyEvent) -> Unit
) {
    return setOnKeyReleased { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnKeyTyped
 */
public fun Scene.onKeyTyped(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(KeyEvent) -> Unit
) {
    return setOnKeyTyped { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnInputMethodTextChanged
 */
public fun Scene.onInputMethodTextChanged(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(InputMethodEvent) -> Unit
) {
    return setOnInputMethodTextChanged { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Scene.setOnContextMenuRequested
 */
public fun Scene.onContextMenuRequested(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ContextMenuEvent) -> Unit
) {
    return setOnContextMenuRequested { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>thirdparty/jfoenix-listeners/src/ktfx/jfoenix/listeners/_JFXDialog.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.jfoenix.listeners

import com.jfoenix.controls.JFXDialog
import com.jfoenix.controls.events.JFXDialogEvent
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see JFXDialog.setOnDialogClosed
 */
public inline fun JFXDialog.onDialogClosed(noinline action: (JFXDialogEvent) -> Unit) {
    return setOnDialogClosed(action)
}

/**
 * @see JFXDialog.setOnDialogOpened
 */
public inline fun JFXDialog.onDialogOpened(noinline action: (JFXDialogEvent) -> Unit) {
    return setOnDialogOpened(action)
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/CheckTreeViewTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.CheckTreeView
import kotlin.test.assertNull

class CheckTreeViewTest : LayoutsTest<KtfxPane, CheckTreeView<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = checkTreeView<String> { }
    override fun KtfxPane.child2() = checkTreeView<String>()
    override fun KtfxPane.child3() = checkTreeView<String> { }

    override fun CheckTreeView<String>.testDefaultValues() {
        assertNull(root)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/QuadCurveToTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.QuadCurveTo
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class QuadCurveToTest : LayoutsTest<KtfxPath, QuadCurveTo>() {

    override fun manager() = KtfxPath()
    override fun KtfxPath.childCount() = elements.size
    override fun child1() = quadCurveTo { }
    override fun KtfxPath.child2() = quadCurveTo()
    override fun KtfxPath.child3() = quadCurveTo { }

    override fun QuadCurveTo.testDefaultValues() {
        assertEquals(0.0, controlX)
        assertEquals(0.0, controlY)
        assertEquals(0.0, x)
        assertEquals(0.0, y)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/BoxTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.Box
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class BoxTest : LayoutsTest<KtfxPane, Box>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = box { }
    override fun KtfxPane.child2() = box()
    override fun KtfxPane.child3() = box { }

    override fun Box.testDefaultValues() {
        assertEquals(Box.DEFAULT_SIZE, width)
        assertEquals(Box.DEFAULT_SIZE, height)
        assertEquals(Box.DEFAULT_SIZE, depth)
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXRadioButtonTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXRadioButton
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class JFXRadioButtonTest : LayoutsTest<KtfxPane, JFXRadioButton>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxRadioButton { }
    override fun KtfxPane.child2() = jfxRadioButton()
    override fun KtfxPane.child3() = jfxRadioButton { }

    override fun JFXRadioButton.testDefaultValues() {
        assertNull(text)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/PasswordFieldTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.PasswordField
import com.hendraanggrian.ktfx.test.LayoutsTest

class PasswordFieldTest : LayoutsTest<KtfxPane, PasswordField>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = passwordField { }
    override fun KtfxPane.child2() = passwordField()
    override fun KtfxPane.child3() = passwordField { }
}

<|start_filename|>thirdparty/jfoenix-coroutines/src/ktfx/jfoenix/coroutines/_JFXDecorator.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixCoroutinesKt")

package ktfx.jfoenix.coroutines

import com.jfoenix.controls.JFXDecorator
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see JFXDecorator.setOnCloseButtonAction
 */
public fun JFXDecorator.onCloseButtonAction(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.() -> Unit
) {
    return setOnCloseButtonAction { GlobalScope.launch(context) { action() } }
}


<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXDecorator.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXDecorator
import javafx.scene.Node
import javafx.stage.Stage
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import kotlin.Boolean
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXDecorator] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.jfxDecorator(
    stage: Stage,
    node: Node,
    fullScreen: Boolean = true,
    max: Boolean = true,
    min: Boolean = true
): JFXDecorator = jfxDecorator(
    stage = stage, node = node, fullScreen = fullScreen, max = max,
    min =
    min
) { }

/**
 * Create a [JFXDecorator] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun jfxDecorator(
    stage: Stage,
    node: Node,
    fullScreen: Boolean = true,
    max: Boolean = true,
    min: Boolean = true,
    configuration: (@KtfxLayoutDslMarker JFXDecorator).() -> Unit
): JFXDecorator {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXDecorator(stage, node, fullScreen, max, min)
    child.configuration()
    return child
}

/**
 * Add a [JFXDecorator] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.jfxDecorator(
    stage: Stage,
    node: Node,
    fullScreen: Boolean = true,
    max: Boolean = true,
    min: Boolean = true,
    configuration: (@KtfxLayoutDslMarker JFXDecorator).() -> Unit
): JFXDecorator {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXDecorator(stage, node, fullScreen, max, min)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXDecorator].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledJFXDecorator(
    stage: Stage,
    node: Node,
    fullScreen: Boolean = true,
    max: Boolean = true,
    min: Boolean = true,
    vararg styleClass: String,
    id: String? = null
): JFXDecorator = styledJFXDecorator(
    stage = stage, node = node, fullScreen = fullScreen, max = max,
    min = min, styleClass = *styleClass, id = id
) { }

/**
 * Add a styled [JFXDecorator] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledJFXDecorator(
    stage: Stage,
    node: Node,
    fullScreen: Boolean = true,
    max: Boolean = true,
    min: Boolean = true,
    vararg styleClass: String,
    id: String? = null
): JFXDecorator = styledJFXDecorator(
    stage = stage, node = node, fullScreen = fullScreen, max = max,
    min = min, styleClass = *styleClass, id = id
) { }

/**
 * Create a styled [JFXDecorator] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledJFXDecorator(
    stage: Stage,
    node: Node,
    fullScreen: Boolean = true,
    max: Boolean = true,
    min: Boolean = true,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXDecorator).() -> Unit
): JFXDecorator {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXDecorator(stage, node, fullScreen, max, min)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXDecorator] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledJFXDecorator(
    stage: Stage,
    node: Node,
    fullScreen: Boolean = true,
    max: Boolean = true,
    min: Boolean = true,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker JFXDecorator).() -> Unit
): JFXDecorator {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = JFXDecorator(stage, node, fullScreen, max, min)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/NumberValueBindingFloatTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.floatPropertyOf
import kotlin.test.Test
import kotlin.test.assertEquals

class NumberValueBindingFloatTest {

    @Test
    fun unaryMinus() = assertEquals(-1f, (-floatPropertyOf(1f)).value)

    @Test
    fun plus() {
        // observable float to double
        assertEquals(3.0, (floatPropertyOf(1f) + 2.0).value)
        assertEquals(3.0, (2.0 + floatPropertyOf(1f)).value)
        // observable float to float
        assertEquals(3f, (floatPropertyOf(1f) + 2f).value)
        assertEquals(3f, (2f + floatPropertyOf(1f)).value)
        // observable float to long
        assertEquals(3f, (floatPropertyOf(1f) + 2L).value)
        assertEquals(3f, (2L + floatPropertyOf(1f)).value)
        // observable float to int
        assertEquals(3f, (floatPropertyOf(1f) + 2).value)
        assertEquals(3f, (2 + floatPropertyOf(1f)).value)
    }

    @Test
    fun minus() {
        // observable float to double
        assertEquals(-1.0, (floatPropertyOf(1f) - 2.0).value)
        assertEquals(1.0, (2.0 - floatPropertyOf(1f)).value)
        // observable float to float
        assertEquals(-1f, (floatPropertyOf(1f) - 2f).value)
        assertEquals(1f, (2f - floatPropertyOf(1f)).value)
        // observable float to long
        assertEquals(-1f, (floatPropertyOf(1f) - 2L).value)
        assertEquals(1f, (2L - floatPropertyOf(1f)).value)
        // observable float to int
        assertEquals(-1f, (floatPropertyOf(1f) - 2).value)
        assertEquals(1f, (2 - floatPropertyOf(1f)).value)
    }

    @Test
    fun times() {
        // observable float to double
        assertEquals(2.0, (floatPropertyOf(1f) * 2.0).value)
        assertEquals(2.0, (2.0 * floatPropertyOf(1f)).value)
        // observable float to float
        assertEquals(2f, (floatPropertyOf(1f) * 2f).value)
        assertEquals(2f, (2f * floatPropertyOf(1f)).value)
        // observable float to long
        assertEquals(2f, (floatPropertyOf(1f) * 2L).value)
        assertEquals(2f, (2L * floatPropertyOf(1f)).value)
        // observable float to int
        assertEquals(2f, (floatPropertyOf(1f) * 2).value)
        assertEquals(2f, (2 * floatPropertyOf(1f)).value)
    }

    @Test
    fun div() {
        // observable float to double
        assertEquals(0.5, (floatPropertyOf(1f) / 2.0).value)
        assertEquals(2.0, (2.0 / floatPropertyOf(1f)).value)
        // observable float to float
        assertEquals(0.5f, (floatPropertyOf(1f) / 2f).value)
        assertEquals(2f, (2f / floatPropertyOf(1f)).value)
        // observable float to long
        assertEquals(0.5f, (floatPropertyOf(1f) / 2L).value)
        assertEquals(2f, (2L / floatPropertyOf(1f)).value)
        // observable float to int
        assertEquals(0.5f, (floatPropertyOf(1f) / 2).value)
        assertEquals(2f, (2 / floatPropertyOf(1f)).value)
    }
}


<|start_filename|>codegen/build.gradle.kts<|end_filename|>
plugins {
    javafx
    kotlin("jvm")
    application
}

javafx {
    modules("javafx.base", "javafx.controls", "javafx.media", "javafx.web")
}

application {
    mainClass.set("$RELEASE_GROUP.$RELEASE_ARTIFACT.codegen.Generator")
}

sourceSets {
    main {
        java.srcDir("src")
    }
    test {
        java.srcDir("tests/src")
    }
}

dependencies {
    implementation(kotlin("stdlib", VERSION_KOTLIN))
    implementation(kotlin("reflect", VERSION_KOTLIN))
    implementation(kotlinx("coroutines-core", VERSION_COROUTINES))
    implementation(kotlinpoetKtx())
    implementation(controlsfx())
    implementation(jfoenix())
    testImplementation(kotlin("test-junit", VERSION_KOTLIN))
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_CubicCurveTo.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.CubicCurveTo
import kotlin.Double
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [CubicCurveTo] to this manager.
 *
 * @return the control added.
 */
public fun PathElementManager.cubicCurveTo(
    controlX1: Double = 0.0,
    controlY1: Double = 0.0,
    controlX2: Double = 0.0,
    controlY2: Double = 0.0,
    x: Double = 0.0,
    y: Double = 0.0
): CubicCurveTo = cubicCurveTo(
    controlX1 = controlX1, controlY1 = controlY1, controlX2 = controlX2,
    controlY2 = controlY2, x = x, y = y
) { }

/**
 * Create a [CubicCurveTo] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun cubicCurveTo(
    controlX1: Double = 0.0,
    controlY1: Double = 0.0,
    controlX2: Double = 0.0,
    controlY2: Double = 0.0,
    x: Double = 0.0,
    y: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker CubicCurveTo).() -> Unit
): CubicCurveTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CubicCurveTo(controlX1, controlY1, controlX2, controlY2, x, y)
    child.configuration()
    return child
}

/**
 * Add a [CubicCurveTo] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun PathElementManager.cubicCurveTo(
    controlX1: Double = 0.0,
    controlY1: Double = 0.0,
    controlX2: Double = 0.0,
    controlY2: Double = 0.0,
    x: Double = 0.0,
    y: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker CubicCurveTo).() -> Unit
): CubicCurveTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = CubicCurveTo(controlX1, controlY1, controlX2, controlY2, x, y)
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-listeners/tests/src/javafx/beans/value/ObservableValueTest.kt<|end_filename|>
package ktfx.listeners

import javafx.beans.Observable
import javafx.beans.value.ObservableValue
import com.hendraanggrian.ktfx.test.BaseObservableValueTest

class ObservableValueTest : BaseObservableValueTest() {

    override fun ObservableValue<String>.callListener(action: (Observable, String, String) -> Unit) {
        listener(action)
    }
}

<|start_filename|>ktfx-commons/src/ktfx/bindings/StringValueBinding.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("StringValueBindingKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.binding.Bindings
import javafx.beans.binding.BooleanBinding
import javafx.beans.binding.IntegerBinding
import javafx.beans.binding.StringExpression
import javafx.beans.value.ObservableStringValue

/** @see StringExpression.isEqualTo */
inline infix fun ObservableStringValue.eq(other: ObservableStringValue): BooleanBinding = Bindings.equal(this, other)

/** @see StringExpression.isEqualTo */
inline infix fun ObservableStringValue.eq(other: String): BooleanBinding = Bindings.equal(this, other)

/** @see StringExpression.isNotEqualTo */
inline infix fun String.eq(other: ObservableStringValue): BooleanBinding = Bindings.equal(this, other)

/** @see StringExpression.isNotEqualTo */
inline infix fun ObservableStringValue.neq(other: ObservableStringValue): BooleanBinding =
    Bindings.notEqual(this, other)

/** @see StringExpression.isNotEqualTo */
inline infix fun ObservableStringValue.neq(other: String): BooleanBinding = Bindings.notEqual(this, other)

/** @see StringExpression.isNotEqualTo */
inline infix fun String.neq(other: ObservableStringValue): BooleanBinding = Bindings.notEqual(this, other)

/** @see StringExpression.isEqualToIgnoreCase */
inline infix fun ObservableStringValue.eqIg(other: ObservableStringValue): BooleanBinding =
    Bindings.equalIgnoreCase(this, other)

/** @see StringExpression.isEqualToIgnoreCase */
inline infix fun ObservableStringValue.eqIg(other: String): BooleanBinding = Bindings.equalIgnoreCase(this, other)

/** @see StringExpression.isEqualToIgnoreCase */
inline infix fun String.eqIg(other: ObservableStringValue): BooleanBinding = Bindings.equalIgnoreCase(this, other)

/** @see StringExpression.isNotEqualToIgnoreCase */
inline infix fun ObservableStringValue.neqIg(other: ObservableStringValue): BooleanBinding =
    Bindings.notEqualIgnoreCase(this, other)

/** @see StringExpression.isNotEqualToIgnoreCase */
inline infix fun ObservableStringValue.neqIg(other: String): BooleanBinding = Bindings.notEqualIgnoreCase(this, other)

/** @see StringExpression.isNotEqualToIgnoreCase */
inline infix fun String.neqIg(other: ObservableStringValue): BooleanBinding = Bindings.notEqualIgnoreCase(this, other)

/** @see StringExpression.greaterThan */
inline infix fun ObservableStringValue.greater(other: ObservableStringValue): BooleanBinding =
    Bindings.greaterThan(this, other)

/** @see StringExpression.greaterThan */
inline infix fun ObservableStringValue.greater(other: String): BooleanBinding = Bindings.greaterThan(this, other)

/** @see StringExpression.greaterThan */
inline infix fun String.greater(other: ObservableStringValue): BooleanBinding = Bindings.greaterThan(this, other)

/** @see StringExpression.lessThan */
inline infix fun ObservableStringValue.less(other: ObservableStringValue): BooleanBinding =
    Bindings.lessThan(this, other)

/** @see StringExpression.lessThan */
inline infix fun ObservableStringValue.less(other: String): BooleanBinding = Bindings.lessThan(this, other)

/** @see StringExpression.lessThan */
inline infix fun String.less(other: ObservableStringValue): BooleanBinding = Bindings.lessThan(this, other)

/** @see StringExpression.greaterThanOrEqualTo */
inline infix fun ObservableStringValue.greaterEq(other: ObservableStringValue): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see StringExpression.greaterThanOrEqualTo */
inline infix fun ObservableStringValue.greaterEq(other: String): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see StringExpression.greaterThanOrEqualTo */
inline infix fun String.greaterEq(other: ObservableStringValue): BooleanBinding =
    Bindings.greaterThanOrEqual(this, other)

/** @see StringExpression.lessThanOrEqualTo */
inline infix fun ObservableStringValue.lessEq(other: ObservableStringValue): BooleanBinding =
    Bindings.lessThanOrEqual(this, other)

/** @see StringExpression.lessThanOrEqualTo */
inline infix fun ObservableStringValue.lessEq(other: String): BooleanBinding = Bindings.lessThanOrEqual(this, other)

/** @see StringExpression.lessThanOrEqualTo */
inline infix fun String.lessEq(other: ObservableStringValue): BooleanBinding = Bindings.lessThanOrEqual(this, other)

/** @see StringExpression.length */
inline fun ObservableStringValue.length(): IntegerBinding = Bindings.length(this)

/** @see StringExpression.isEmpty */
inline fun ObservableStringValue.isEmpty(): BooleanBinding = Bindings.isEmpty(this)

/** @see StringExpression.isNotEmpty */
inline fun ObservableStringValue.isNotEmpty(): BooleanBinding = Bindings.isNotEmpty(this)


<|start_filename|>testing/listeners-coroutines-jfoenix/src/com/jfoenix/controls/BaseJFXDecoratorTest.kt<|end_filename|>
package ktfx.jfoenix.test

import com.jfoenix.controls.JFXDecorator
import javafx.scene.control.Label
import javafx.stage.Stage
import org.testfx.framework.junit.ApplicationTest
import kotlin.test.Test

abstract class BaseJFXDecoratorTest : ApplicationTest() {
    private lateinit var decorator: JFXDecorator

    abstract fun JFXDecorator.callOnCloseButtonAction(action: () -> Unit)

    override fun start(stage: Stage) {
        decorator = JFXDecorator(stage, Label("Hello world"))
    }

    @Test
    fun onCloseButtonAction() {
        decorator.callOnCloseButtonAction { }
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/layout/PaneTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.layout.Pane
import com.hendraanggrian.ktfx.test.LayoutsTest

class PaneTest : LayoutsTest<KtfxPane, Pane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = pane { }
    override fun KtfxPane.child2() = pane()
    override fun KtfxPane.child3() = pane { }
}

<|start_filename|>thirdparty/jfoenix-coroutines/src/ktfx/jfoenix/coroutines/_JFXDrawer.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixCoroutinesKt")

package ktfx.jfoenix.coroutines

import com.jfoenix.controls.JFXDrawer
import com.jfoenix.controls.events.JFXDrawerEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see JFXDrawer.setOnDrawerClosed
 */
public fun JFXDrawer.onDrawerClosed(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(JFXDrawerEvent) -> Unit
) {
    return setOnDrawerClosed { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see JFXDrawer.setOnDrawerClosing
 */
public fun JFXDrawer.onDrawerClosing(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(JFXDrawerEvent) -> Unit
) {
    return setOnDrawerClosing { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see JFXDrawer.setOnDrawerOpened
 */
public fun JFXDrawer.onDrawerOpened(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(JFXDrawerEvent) -> Unit
) {
    return setOnDrawerOpened { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see JFXDrawer.setOnDrawerOpening
 */
public fun JFXDrawer.onDrawerOpening(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(JFXDrawerEvent) -> Unit
) {
    return setOnDrawerOpening { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/layouts/LayoutsFactory.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.layouts

import com.hendraanggrian.kotlinpoet.asNullable
import com.hendraanggrian.kotlinpoet.memberOf
import com.hendraanggrian.kotlinpoet.parameterizedBy
import com.squareup.kotlinpoet.ParameterSpec
import com.squareup.kotlinpoet.TypeVariableName
import com.hendraanggrian.kotlinpoet.dsl.ParameterSpecHandlerScope
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.scene.Node
import javafx.scene.control.ProgressBar
import javafx.scene.control.TreeItem
import javafx.scene.paint.Color
import java.time.LocalDate
import kotlin.reflect.KClass

open class LayoutsFactory(
    val path: String,
    val packageName: String,
    val className: String
) {
    companion object {
        fun ParameterSpecHandlerScope.text() = "text"(String::class.asNullable()) { defaultValue("null") }
        fun ParameterSpecHandlerScope.graphic() = "graphic"(Node::class.asNullable()) { defaultValue("null") }
        fun ParameterSpecHandlerScope.content() = "content"(Node::class.asNullable()) { defaultValue("null") }
        fun ParameterSpecHandlerScope.progress() =
            "progress"<Double> { defaultValue("%M", ProgressBar::class.memberOf("INDETERMINATE_PROGRESS")) }

        fun ParameterSpecHandlerScope.color() =
            "color"<Color> { defaultValue("%M", Color::class.memberOf("WHITE")) }

        fun ParameterSpecHandlerScope.date() = "date"(LocalDate::class.asNullable()) { defaultValue("null") }

        fun ParameterSpecHandlerScope.items(name: TypeVariableName) =
            "items"(ObservableList::class.parameterizedBy(name)) {
                defaultValue("%M()", FXCollections::class.memberOf("observableArrayList"))
            }

        fun ParameterSpecHandlerScope.treeItem(name: String, variable: TypeVariableName) =
            name(TreeItem::class.parameterizedBy(variable).asNullable()) { defaultValue("null") }

        fun ParameterSpecHandlerScope.slider(value: String) {
            "min"<Double> { defaultValue("0.0") }
            "max"<Double> { defaultValue("100.0") }
            "value"<Double> { defaultValue(value) }
        }
    }

    val entries = mutableListOf<LayoutsEntry>()

    operator fun KClass<*>.invoke(
        vararg typeVariables: TypeVariableName,
        customClass: Boolean = false,
        configuration: ParameterSpecHandlerScope.() -> Unit = { }
    ) {
        val parameters = mutableListOf<ParameterSpec>()
        ParameterSpecHandlerScope(parameters).configuration()
        entries += LayoutsEntry(packageName, this, parameters, typeVariables.asList(), customClass = customClass)
    }
}

<|start_filename|>ktfx-commons/tests/src/ktfx/time/DurationTest.kt<|end_filename|>
package ktfx.time

import javafx.util.Duration
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.time.ExperimentalTime

class DurationTest {

    @Test
    fun toDuration() {
        assertEquals(5000.milliseconds, "5000ms".toDuration())
        assertEquals(500.seconds, "500s".toDuration())
        assertEquals(50.minutes, "50m".toDuration())
        assertEquals(5.hours, "5h".toDuration())
    }

    @Test
    fun ms() {
        assertEquals(Duration.millis(5000.0), 5000.milliseconds)
        assertEquals(Duration.millis(5000.0), 5000L.milliseconds)
        assertEquals(Duration.millis(5000.0), 5000.0.milliseconds)
    }

    @Test
    fun s() {
        assertEquals(Duration.seconds(500.0), 500.seconds)
        assertEquals(Duration.seconds(500.0), 500L.seconds)
        assertEquals(Duration.seconds(500.0), 500.0.seconds)
    }

    @Test
    fun m() {
        assertEquals(Duration.minutes(50.0), 50.minutes)
        assertEquals(Duration.minutes(50.0), 50L.minutes)
        assertEquals(Duration.minutes(50.0), 50.0.minutes)
    }

    @Test
    fun h() {
        assertEquals(Duration.hours(5.0), 5.hours)
        assertEquals(Duration.hours(5.0), 5L.hours)
        assertEquals(Duration.hours(5.0), 5.0.hours)
    }

    @Test
    fun plus() = assertEquals(2.0.milliseconds, Duration.ONE + Duration.ONE)

    @Test
    fun minus() = assertEquals(3.0.seconds, 5.0.seconds - 2.0.seconds)

    @Test
    fun times() {
        assertEquals(10.milliseconds, 2.milliseconds * 5)
        assertEquals(10.0.milliseconds, 2.0.milliseconds * 5.0)
    }

    @Test
    fun div() {
        assertEquals(Duration.INDEFINITE, 100.milliseconds / 0)
        assertEquals(Duration.INDEFINITE, 100.0.milliseconds / 0.0)
    }

    @Test
    fun unaryMinus() = assertEquals(Duration.ONE.negate(), (-1).milliseconds)

    @ExperimentalTime
    @Test
    fun toKotlinDuration() {
        val aSecond = 1.seconds.toKotlinDuration()
        assertEquals(1000, aSecond.inWholeMilliseconds)
    }

    @ExperimentalTime
    @Test
    fun toFxDuration() {
        val aSecond = kotlin.time.Duration.seconds(1).toFxDuration()
        assertEquals(1000.0, aSecond.toMillis())
    }
}


<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/BindingsDoubleTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.booleanPropertyOf
import ktfx.doublePropertyOf
import ktfx.floatPropertyOf
import ktfx.intPropertyOf
import ktfx.longPropertyOf
import ktfx.propertyOf
import ktfx.time.minutes
import kotlin.test.Test
import kotlin.test.assertEquals

class BindingsDoubleTest {

    @Test
    fun multipleDependencies() {
        val dependency1 = doublePropertyOf(1.0)
        val dependency2 = doublePropertyOf(2.0)
        val binding1 = doubleBindingOf(dependency1, dependency2) { dependency1.value + dependency2.value }
        assertEquals(3.0, binding1.value)
        dependency1.value++
        assertEquals(4.0, binding1.value)

        val dependency3 = doublePropertyOf(1.0)
        val dependency4 = doublePropertyOf(2.0)
        val binding2 = doubleBindingOf(listOf(dependency3, dependency4)) { dependency3.value + dependency4.value }
        assertEquals(3.0, binding2.value)
        dependency3.value++
        assertEquals(4.0, binding2.value)
    }

    @Test
    fun anyDependency() {
        val dependency = propertyOf(1.minutes)
        val binding = dependency.asDouble { it?.toMillis() ?: 0.0 }
        assertEquals(60000.0, binding.value)
        dependency.value = null
        assertEquals(0.0, binding.value)
    }

    @Test
    fun booleanDependency() {
        val dependency = booleanPropertyOf()
        val binding = dependency.asDouble { if (it) Double.MAX_VALUE else Double.MIN_VALUE }
        assertEquals(Double.MIN_VALUE, binding.value)
        dependency.value = true
        assertEquals(Double.MAX_VALUE, binding.value)
    }

    @Test
    fun doubleDependency() {
        val dependency = doublePropertyOf()
        val binding = dependency.asDouble { it }
        assertEquals(0.0, binding.value)
        dependency.value = Double.MAX_VALUE
        assertEquals(Double.MAX_VALUE, binding.value)
    }

    @Test
    fun floatDependency() {
        val dependency = floatPropertyOf()
        val binding = dependency.asDouble { it.toDouble() }
        assertEquals(0.0, binding.value)
        dependency.value = Float.MAX_VALUE
        assertEquals(Float.MAX_VALUE.toDouble(), binding.value)
    }

    @Test
    fun intDependency() {
        val dependency = intPropertyOf()
        val binding = dependency.asDouble { it.toDouble() }
        assertEquals(0.0, binding.value)
        dependency.value = Int.MAX_VALUE
        assertEquals(Int.MAX_VALUE.toDouble(), binding.value)
    }

    @Test
    fun longDependency() {
        val dependency = longPropertyOf()
        val binding = dependency.asDouble { it.toDouble() }
        assertEquals(0.0, binding.value)
        dependency.value = Long.MAX_VALUE
        assertEquals(Long.MAX_VALUE.toDouble(), binding.value)
    }
}


<|start_filename|>testing/listeners-coroutines/src/com/hendraanggrian/ktfx/test/events/FakeMouseDragEvent.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.event.EventType
import javafx.scene.input.MouseButton
import javafx.scene.input.MouseDragEvent
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNull

/**
 * @receiver source of this fake event.
 */
fun Any.assertFakeMouseDragEvent(actual: MouseDragEvent, expectedType: EventType<MouseDragEvent>) {
    assertEquals(this, actual.source)
    assertEquals(FakeEventTarget, actual.target)
    assertEquals(expectedType, actual.eventType)
    assertEquals(0.0, actual.x)
    assertEquals(0.0, actual.y)
    assertEquals(0.0, actual.sceneX)
    assertEquals(0.0, actual.sceneY)
    assertFalse(actual.isShiftDown)
    assertFalse(actual.isControlDown)
    assertFalse(actual.isAltDown)
    assertFalse(actual.isMetaDown)
    assertFalse(actual.isPrimaryButtonDown)
    assertFalse(actual.isMiddleButtonDown)
    assertFalse(actual.isSecondaryButtonDown)
    assertFalse(actual.isSynthesized)
    assertFalse(actual.isPopupTrigger)
    assertEquals(FakePickResult, actual.pickResult)
    assertNull(actual.gestureSource)
}

/**
 * @receiver source of this fake event.
 */
fun Any.fakeMouseDragEventOf(eventType: EventType<MouseDragEvent>) = MouseDragEvent(
    this, FakeEventTarget, eventType,
    0.0, 0.0, 0.0, 0.0,
    MouseButton.PRIMARY, 1,
    false, false, false, false,
    false, false, false,
    false, false, FakePickResult,
    null
)

<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/BindingsStringTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.booleanPropertyOf
import ktfx.doublePropertyOf
import ktfx.floatPropertyOf
import ktfx.intPropertyOf
import ktfx.longPropertyOf
import ktfx.propertyOf
import ktfx.stringPropertyOf
import ktfx.time.minutes
import kotlin.test.Test
import kotlin.test.assertEquals

class BindingsStringTest {

    @Test
    fun multipleDependencies() {
        val dependency1 = stringPropertyOf("Hello")
        val dependency2 = stringPropertyOf("World")
        val binding1 = stringBindingOf(dependency1, dependency2) { dependency1.value + ' ' + dependency2.value }
        assertEquals("Hello World", binding1.value)
        dependency1.value = "Goodbye"
        assertEquals("Goodbye World", binding1.value)

        val dependency3 = stringPropertyOf("Hello")
        val dependency4 = stringPropertyOf("World")
        val binding2 = stringBindingOf(listOf(dependency3, dependency4)) { dependency3.value + ' ' + dependency4.value }
        assertEquals("Hello World", binding2.value)
        dependency3.value = "Goodbye"
        assertEquals("Goodbye World", binding2.value)
    }

    @Test
    fun anyDependency() {
        val dependency = propertyOf(1.minutes)
        val binding = dependency.asString { it.toString() }
        assertEquals("60000.0 ms", binding.value)
        dependency.value = null
        assertEquals("null", binding.value)
    }

    @Test
    fun booleanDependency() {
        val dependency = booleanPropertyOf()
        val binding = dependency.asString { it.toString() }
        assertEquals("false", binding.value)
        dependency.value = true
        assertEquals("true", binding.value)
    }

    @Test
    fun doubleDependency() {
        val dependency = doublePropertyOf()
        val binding = dependency.asString { it.toString() }
        assertEquals("0.0", binding.value)
        dependency.value = Double.MAX_VALUE
        assertEquals(Double.MAX_VALUE.toString(), binding.value)
    }

    @Test
    fun floatDependency() {
        val dependency = floatPropertyOf()
        val binding = dependency.asString { it.toString() }
        assertEquals("0.0", binding.value)
        dependency.value = Float.MAX_VALUE
        assertEquals(Float.MAX_VALUE.toString(), binding.value)
    }

    @Test
    fun intDependency() {
        val dependency = intPropertyOf()
        val binding = dependency.asString { it.toString() }
        assertEquals("0", binding.value)
        dependency.value = Int.MAX_VALUE
        assertEquals(Int.MAX_VALUE.toString(), binding.value)
    }

    @Test
    fun longDependency() {
        val dependency = longPropertyOf()
        val binding = dependency.asString { it.toString() }
        assertEquals("0", binding.value)
        dependency.value = Long.MAX_VALUE
        assertEquals(Long.MAX_VALUE.toString(), binding.value)
    }
}


<|start_filename|>ktfx-commons/tests/src/com/hendraanggrian/ktfx/test/BaseArraysTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.collections.ObservableArray
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

/** All observable array tests must follow this convention. */
abstract class BaseArraysTest<T : ObservableArray<T>, PrimitiveArray, E> {

    abstract val typedArray: Array<E>
    abstract val primitiveArray: PrimitiveArray

    abstract fun of(): T
    abstract fun of(values: Array<E>): T

    @Test
    fun creating() {
        val empty = of()
        assertEquals(0, empty.size())

        val filled = of(typedArray)
        assertNotEquals(0, filled.size())
    }

    abstract fun PrimitiveArray.to(): T

    @Test
    fun converting() {
        val typedArray = primitiveArray.to()
        assertNotEquals(0, typedArray.size())
    }
}


<|start_filename|>testing/listeners-coroutines/src/javafx/collections/BaseObservableSetTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.collections.FXCollections
import javafx.collections.ObservableSet
import javafx.collections.SetChangeListener
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

abstract class BaseObservableSetTest {

    abstract fun <E> ObservableSet<E>.callListener(action: (SetChangeListener.Change<out E>) -> Unit)

    @Test
    fun listener() {
        val set = FXCollections.observableSet<String>()
        set.callListener {
            assertTrue(it.wasAdded())
            assertEquals("Hello world", it.elementAdded)
        }
        set.add("Hello world")
    }
}

<|start_filename|>ktfx-layouts/src/javafx/scene/layout/KtfxFlowPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.layouts

import javafx.geometry.Insets
import javafx.geometry.Orientation
import javafx.scene.Node
import javafx.scene.layout.FlowPane
import kotlin.contracts.ExperimentalContracts

/**
 * [FlowPane] with dynamic-layout dsl support.
 * Invoking dsl will add its children.
 */
open class KtfxFlowPane(orientation: Orientation, hgap: Double, vgap: Double) :
    FlowPane(orientation, hgap, vgap),
    NodeManager {

    constructor(orientation: Orientation, gap: Double) : this(orientation, gap, gap)

    final override fun <C : Node> addChild(child: C): C = child.also { children += it }

    /** Children margin in this layout. */
    inline var Node.margin: Insets?
        @JvmName("getMargin2") get() = getMargin(this)
        @JvmName("setMargin2") set(value) = setMargin(this, value)

    /** Configure [margin] fluidly. */
    fun <C : Node> C.margin(insets: Insets): C {
        margin = insets
        return this
    }

    /** Clear children constraints. */
    @JvmName("clearConstraints2")
    inline fun Node.clearConstraints(): Unit = clearConstraints(this)
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/animation/AnimationTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.animation.Animation
import javafx.event.ActionEvent
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseAnimationTest

class AnimationTest : BaseAnimationTest() {

    override fun Animation.callOnFinished(action: (ActionEvent) -> Unit) =
        onFinished(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_ToggleSwitch.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.ToggleSwitch
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [ToggleSwitch] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.toggleSwitch(text: String? = null): ToggleSwitch = toggleSwitch(text = text) { }

/**
 * Create a [ToggleSwitch] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun toggleSwitch(
    text: String? = null,
    configuration: (
        @KtfxLayoutDslMarker    
        ToggleSwitch
    ).() -> Unit
): ToggleSwitch {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ToggleSwitch(text)
    child.configuration()
    return child
}

/**
 * Add a [ToggleSwitch] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.toggleSwitch(
    text: String? = null,
    configuration: (@KtfxLayoutDslMarker ToggleSwitch).() -> Unit
): ToggleSwitch {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ToggleSwitch(text)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [ToggleSwitch].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledToggleSwitch(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null
): ToggleSwitch = styledToggleSwitch(text = text, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [ToggleSwitch] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledToggleSwitch(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null
): ToggleSwitch = styledToggleSwitch(text = text, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [ToggleSwitch] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledToggleSwitch(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker ToggleSwitch).() -> Unit
): ToggleSwitch {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ToggleSwitch(text)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [ToggleSwitch] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledToggleSwitch(
    text: String? = null,
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker ToggleSwitch).() -> Unit
): ToggleSwitch {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = ToggleSwitch(text)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ProgressBarTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.ProgressBar
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class ProgressBarTest : LayoutsTest<KtfxPane, ProgressBar>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = progressBar { }
    override fun KtfxPane.child2() = progressBar()
    override fun KtfxPane.child3() = progressBar { }

    override fun ProgressBar.testDefaultValues() {
        assertEquals(ProgressBar.INDETERMINATE_PROGRESS, progress)
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/textfield/CustomTextFieldTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.textfield.CustomTextField

class CustomTextFieldTest : LayoutsTest<KtfxPane, CustomTextField>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = customTextField { }
    override fun KtfxPane.child2() = customTextField()
    override fun KtfxPane.child3() = customTextField { }
}

<|start_filename|>build.gradle.kts<|end_filename|>
buildscript {
    repositories {
        mavenCentral()
        gradlePluginPortal()
    }
    dependencies {
        classpath(kotlin("gradle-plugin", VERSION_KOTLIN))
        classpath(javafx)
        classpath(dokka)
        classpath(`git-publish`)
    }
}

allprojects {
    repositories {
        jcenter() // TestFX hasn't migrated
        mavenCentral()
        maven(REPOSITORIES_OSSRH_SNAPSHOTS)
    }
}

<|start_filename|>testing/commons/src/com/hendraanggrian/ktfx/test/TableColumnTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import kotlin.test.Test

abstract class TableColumnTest {

    @Test
    fun columns() {
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXDefaultChipTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXChipView
import com.jfoenix.controls.JFXDefaultChip
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class JFXDefaultChipTest : LayoutsTest<KtfxPane, JFXDefaultChip<String>>() {
    private lateinit var jfxChipView: JFXChipView<String>

    override fun onCreate() {
        super.onCreate()
        jfxChipView = JFXChipView()
    }

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxDefaultChip(jfxChipView, "Yo") { }
    override fun KtfxPane.child2() = jfxDefaultChip(jfxChipView, "Yo")
    override fun KtfxPane.child3() = jfxDefaultChip(jfxChipView, "Yo") { }

    override fun JFXDefaultChip<String>.testDefaultValues() {
        assertEquals(jfxChipView, chipView)
        assertEquals("Yo", item)
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXChipViewTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXChipView
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXChipViewTest : LayoutsTest<KtfxPane, JFXChipView<String>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxChipView<String> { }
    override fun KtfxPane.child2() = jfxChipView<String>()
    override fun KtfxPane.child3() = jfxChipView<String> { }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/image/ImageViewTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.image.ImageView
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class ImageViewTest : LayoutsTest<KtfxPane, ImageView>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = imageView { }
    override fun KtfxPane.child2() = imageView()
    override fun KtfxPane.child3() = imageView { }

    override fun ImageView.testDefaultValues() {
        assertNull(image)
    }
}

<|start_filename|>testing/layouts/src/com/hendraanggrian/ktfx/test/LayoutsTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

/** There are 3 ways to create/add a child. This test ensures that each way produces the same child result. */
abstract class LayoutsTest<M : Any, C> {
    private lateinit var manager: M

    @BeforeTest open fun onCreate() {
        initToolkit()
        manager = manager()
    }

    abstract fun manager(): M
    abstract fun M.childCount(): Int
    abstract fun child1(): C
    abstract fun M.child2(): C
    abstract fun M.child3(): C

    /** Override to test default values. */
    open fun C.testDefaultValues() {
    }

    @Test
    fun createChildWithBuilder() {
        val child = child1()
        child.testDefaultValues()
        assertEquals(0, manager.childCount())
    }

    @Test
    fun addChild() {
        val child = manager.child3()
        child.testDefaultValues()
        assertEquals(1, manager.childCount())
    }

    @Test
    fun addChildWithBuilder() {
        val child = manager.child2()
        child.testDefaultValues()
        assertEquals(1, manager.childCount())
    }
}

<|start_filename|>thirdparty/controlsfx-layouts/src/ktfx/controlsfx/layouts/_GridView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.controlsfx.layouts

import javafx.collections.FXCollections.observableArrayList
import javafx.collections.ObservableList
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import org.controlsfx.control.GridView
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [GridView] to this manager.
 *
 * @return the control added.
 */
public fun <T> NodeManager.gridView(items: ObservableList<T> = observableArrayList()): GridView<T> =
    gridView(items = items) { }

/**
 * Create a [GridView] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun <T> gridView(
    items: ObservableList<T> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker GridView<T>).() -> Unit
): GridView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = GridView<T>(items)
    child.configuration()
    return child
}

/**
 * Add a [GridView] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun <T> NodeManager.gridView(
    items: ObservableList<T> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker GridView<T>).() -> Unit
): GridView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = GridView<T>(items)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [GridView].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun <T> styledGridView(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): GridView<T> = styledGridView(items = items, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [GridView] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun <T> NodeManager.styledGridView(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): GridView<T> = styledGridView(items = items, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [GridView] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun <T> styledGridView(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker GridView<T>).() -> Unit
): GridView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = GridView<T>(items)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [GridView] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun <T> NodeManager.styledGridView(
    items: ObservableList<T> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker GridView<T>).() -> Unit
): GridView<T> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = GridView<T>(items)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>testing/commons/src/com/hendraanggrian/ktfx/test/SampleImageView.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.scene.image.ImageView

class SampleImageView : ImageView("sample.png")

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXDatePickerTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXDatePicker
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class JFXDatePickerTest : LayoutsTest<KtfxPane, JFXDatePicker>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxDatePicker { }
    override fun KtfxPane.child2() = jfxDatePicker()
    override fun KtfxPane.child3() = jfxDatePicker { }

    override fun JFXDatePicker.testDefaultValues() {
        assertNull(value)
    }
}

<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_TableView.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.TableColumn
import javafx.scene.control.TableView
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Int
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see TableView.setOnSort
 */
public fun <S> TableView<S>.onSort(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(SortEvent<TableView<S>>) -> Unit
) {
    return setOnSort { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TableView.setOnScrollTo
 */
public fun <S> TableView<S>.onScrollTo(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ScrollToEvent<Int>) -> Unit
) {
    return setOnScrollTo { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see TableView.setOnScrollToColumn
 */
public fun <S> TableView<S>.onScrollToColumn(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(ScrollToEvent<TableColumn<S, *>>) -> Unit
) {
    return setOnScrollToColumn { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/layout/TilePaneTest.kt<|end_filename|>
package ktfx.layouts

import javafx.geometry.Orientation
import javafx.scene.layout.TilePane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class TilePaneTest : LayoutsTest<KtfxPane, TilePane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = tilePane { }
    override fun KtfxPane.child2() = tilePane()
    override fun KtfxPane.child3() = tilePane { }

    override fun TilePane.testDefaultValues() {
        assertEquals(Orientation.HORIZONTAL, orientation)
        assertEquals(0.0, hgap)
        assertEquals(0.0, vgap)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/ArcTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.Arc
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class ArcTest : LayoutsTest<KtfxPane, Arc>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = arc { }
    override fun KtfxPane.child2() = arc()
    override fun KtfxPane.child3() = arc { }

    override fun Arc.testDefaultValues() {
        assertEquals(0.0, centerX)
        assertEquals(0.0, centerY)
        assertEquals(0.0, radiusX)
        assertEquals(0.0, radiusY)
        assertEquals(0.0, startAngle)
        assertEquals(0.0, length)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/RadioButtonTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.RadioButton
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class RadioButtonTest : LayoutsTest<KtfxPane, RadioButton>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = radioButton { }
    override fun KtfxPane.child2() = radioButton()
    override fun KtfxPane.child3() = radioButton { }

    override fun RadioButton.testDefaultValues() {
        assertNull(text)
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/SeparatorTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.Separator
import com.hendraanggrian.ktfx.test.LayoutsTest

class SeparatorTest : LayoutsTest<KtfxPane, Separator>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = separator { }
    override fun KtfxPane.child2() = separator()
    override fun KtfxPane.child3() = separator { }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_PieChart.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.collections.FXCollections.observableArrayList
import javafx.collections.ObservableList
import javafx.scene.chart.PieChart
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [PieChart] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.pieChart(`data`: ObservableList<PieChart.Data> = observableArrayList()):
    PieChart = pieChart(data = data) { }

/**
 * Create a [PieChart] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun pieChart(
    `data`: ObservableList<PieChart.Data> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker PieChart).() -> Unit
): PieChart {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PieChart(data)
    child.configuration()
    return child
}

/**
 * Add a [PieChart] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun NodeManager.pieChart(
    `data`: ObservableList<PieChart.Data> =
        observableArrayList(),
    configuration: (@KtfxLayoutDslMarker PieChart).() -> Unit
):
    PieChart {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PieChart(data)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [PieChart].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun styledPieChart(
    `data`: ObservableList<PieChart.Data> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): PieChart = styledPieChart(data = data, styleClass = *styleClass, id = id) { }

/**
 * Add a styled [PieChart] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun NodeManager.styledPieChart(
    `data`: ObservableList<PieChart.Data> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): PieChart = styledPieChart(data = data, styleClass = *styleClass, id = id) { }

/**
 * Create a styled [PieChart] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun styledPieChart(
    `data`: ObservableList<PieChart.Data> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker PieChart).() -> Unit
): PieChart {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PieChart(data)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [PieChart] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun NodeManager.styledPieChart(
    `data`: ObservableList<PieChart.Data> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker PieChart).() -> Unit
): PieChart {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = PieChart(data)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/ArcToTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.ArcTo
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals
import kotlin.test.assertFalse

class ArcToTest : LayoutsTest<KtfxPath, ArcTo>() {

    override fun manager() = KtfxPath()
    override fun KtfxPath.childCount() = elements.size
    override fun child1() = arcTo { }
    override fun KtfxPath.child2() = arcTo()
    override fun KtfxPath.child3() = arcTo { }

    override fun ArcTo.testDefaultValues() {
        assertEquals(0.0, radiusX)
        assertEquals(0.0, radiusY)
        assertEquals(0.0, xAxisRotation)
        assertEquals(0.0, radiusY)
        assertEquals(0.0, x)
        assertEquals(0.0, y)
        assertFalse(isLargeArcFlag)
        assertFalse(isSweepFlag)
    }
}

<|start_filename|>ktfx-layouts/src/ktfx/layouts/_AreaChart.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.collections.FXCollections.observableArrayList
import javafx.collections.ObservableList
import javafx.scene.chart.AreaChart
import javafx.scene.chart.Axis
import javafx.scene.chart.XYChart
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add an [AreaChart] to this manager.
 *
 * @return the control added.
 */
public fun <X, Y> NodeManager.areaChart(
    x: Axis<X>,
    y: Axis<Y>,
    `data`: ObservableList<XYChart.Series<X, Y>> = observableArrayList()
): AreaChart<X, Y> = areaChart(x = x, y = y, data = data) { }

/**
 * Create an [AreaChart] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun <X, Y> areaChart(
    x: Axis<X>,
    y: Axis<Y>,
    `data`: ObservableList<XYChart.Series<X, Y>> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker AreaChart<X, Y>).() -> Unit
): AreaChart<X, Y> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = AreaChart<X, Y>(x, y, data)
    child.configuration()
    return child
}

/**
 * Add an [AreaChart] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun <X, Y> NodeManager.areaChart(
    x: Axis<X>,
    y: Axis<Y>,
    `data`: ObservableList<XYChart.Series<X, Y>> = observableArrayList(),
    configuration: (@KtfxLayoutDslMarker AreaChart<X, Y>).() -> Unit
): AreaChart<X, Y> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = AreaChart<X, Y>(x, y, data)
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [AreaChart].
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control created.
 */
public fun <X, Y> styledAreaChart(
    x: Axis<X>,
    y: Axis<Y>,
    `data`: ObservableList<XYChart.Series<X, Y>> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): AreaChart<X, Y> = styledAreaChart(x = x, y = y, data = data, styleClass = *styleClass, id = id) {
}

/**
 * Add a styled [AreaChart] to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 *
 * @return the styled control added.
 */
public fun <X, Y> NodeManager.styledAreaChart(
    x: Axis<X>,
    y: Axis<Y>,
    `data`: ObservableList<XYChart.Series<X, Y>> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null
): AreaChart<X, Y> = styledAreaChart(x = x, y = y, data = data, styleClass = *styleClass, id = id) {
}

/**
 * Create a styled [AreaChart] with configuration block.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control created.
 */
public inline fun <X, Y> styledAreaChart(
    x: Axis<X>,
    y: Axis<Y>,
    `data`: ObservableList<XYChart.Series<X, Y>> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker AreaChart<X, Y>).() -> Unit
): AreaChart<X, Y> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = AreaChart<X, Y>(x, y, data)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [AreaChart] with configuration block to this manager.
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 *
 * @return the styled control added.
 */
public inline fun <X, Y> NodeManager.styledAreaChart(
    x: Axis<X>,
    y: Axis<Y>,
    `data`: ObservableList<XYChart.Series<X, Y>> = observableArrayList(),
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker AreaChart<X, Y>).() -> Unit
): AreaChart<X, Y> {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = AreaChart<X, Y>(x, y, data)
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXTogglePaneTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTogglePane
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest

class JFXTogglePaneTest : LayoutsTest<KtfxPane, JFXTogglePane>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxTogglePane { }
    override fun KtfxPane.child2() = jfxTogglePane()
    override fun KtfxPane.child3() = jfxTogglePane { }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXTreeTableViewTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXTreeTableView
import com.jfoenix.controls.datamodels.treetable.RecursiveTreeObject
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertNull

class JFXTreeTableViewTest : LayoutsTest<KtfxPane, JFXTreeTableView<JFXTreeTableViewTest.Person>>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxTreeTableView<Person> { }
    override fun KtfxPane.child2() = jfxTreeTableView<Person>()
    override fun KtfxPane.child3() = jfxTreeTableView<Person> { }

    override fun JFXTreeTableView<Person>.testDefaultValues() {
        assertNull(root)
    }

    class Person : RecursiveTreeObject<Person>()
}

<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/NumberValueBindingDoubleTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.doublePropertyOf
import ktfx.intPropertyOf
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue

class NumberValueBindingDoubleTest {

    @Test
    fun unaryMinus() = assertEquals(-1.0, (-doublePropertyOf(1.0)).value)

    @Test
    fun plus() {
        // observable double to observable number
        assertEquals(3.0, (doublePropertyOf(1.0) + doublePropertyOf(2.0)).value)
        // observable double to double
        assertEquals(3.0, (doublePropertyOf(1.0) + 2.0).value)
        assertEquals(3.0, (2.0 + doublePropertyOf(1.0)).value)
        // observable double to float
        assertEquals(3.0, (doublePropertyOf(1.0) + 2f).value)
        assertEquals(3.0, (2f + doublePropertyOf(1.0)).value)
        // observable double to long
        assertEquals(3.0, (doublePropertyOf(1.0) + 2L).value)
        assertEquals(3.0, (2L + doublePropertyOf(1.0)).value)
        // observable double to int
        assertEquals(3.0, (doublePropertyOf(1.0) + 2).value)
        assertEquals(3.0, (2 + doublePropertyOf(1.0)).value)
    }

    @Test
    fun minus() {
        // observable double to observable number
        assertEquals(-1.0, (doublePropertyOf(1.0) - doublePropertyOf(2.0)).value)
        // observable double to double
        assertEquals(-1.0, (doublePropertyOf(1.0) - 2.0).value)
        assertEquals(1.0, (2.0 - doublePropertyOf(1.0)).value)
        // observable double to float
        assertEquals(-1.0, (doublePropertyOf(1.0) - 2f).value)
        assertEquals(1.0, (2f - doublePropertyOf(1.0)).value)
        // observable double to long
        assertEquals(-1.0, (doublePropertyOf(1.0) - 2L).value)
        assertEquals(1.0, (2L - doublePropertyOf(1.0)).value)
        // observable double to int
        assertEquals(-1.0, (doublePropertyOf(1.0) - 2).value)
        assertEquals(1.0, (2 - doublePropertyOf(1.0)).value)
    }

    @Test
    fun times() {
        // observable double to observable number
        assertEquals(2.0, (doublePropertyOf(1.0) * doublePropertyOf(2.0)).value)
        // observable double to double
        assertEquals(2.0, (doublePropertyOf(1.0) * 2.0).value)
        assertEquals(2.0, (2.0 * doublePropertyOf(1.0)).value)
        // observable double to float
        assertEquals(2.0, (doublePropertyOf(1.0) * 2f).value)
        assertEquals(2.0, (2f * doublePropertyOf(1.0)).value)
        // observable double to long
        assertEquals(2.0, (doublePropertyOf(1.0) * 2L).value)
        assertEquals(2.0, (2L * doublePropertyOf(1.0)).value)
        // observable double to int
        assertEquals(2.0, (doublePropertyOf(1.0) * 2).value)
        assertEquals(2.0, (2 * doublePropertyOf(1.0)).value)
    }

    @Test
    fun div() {
        // observable double to observable number
        assertEquals(0.5, (doublePropertyOf(1.0) / doublePropertyOf(2.0)).value)
        // observable double to double
        assertEquals(0.5, (doublePropertyOf(1.0) / 2.0).value)
        assertEquals(2.0, (2.0 / doublePropertyOf(1.0)).value)
        // observable double to float
        assertEquals(0.5, (doublePropertyOf(1.0) / 2f).value)
        assertEquals(2.0, (2f / doublePropertyOf(1.0)).value)
        // observable double to long
        assertEquals(0.5, (doublePropertyOf(1.0) / 2L).value)
        assertEquals(2.0, (2L / doublePropertyOf(1.0)).value)
        // observable double to int
        assertEquals(0.5, (doublePropertyOf(1.0) / 2).value)
        assertEquals(2.0, (2 / doublePropertyOf(1.0)).value)
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/layout/VBoxTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.layout.VBox
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class VBoxTest : LayoutsTest<KtfxPane, VBox>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = vbox { }
    override fun KtfxPane.child2() = vbox()
    override fun KtfxPane.child3() = vbox { }

    override fun VBox.testDefaultValues() {
        assertEquals(0.0, spacing)
    }
}

<|start_filename|>thirdparty/jfoenix-commons/tests/src/ktfx/jfoenix/dialogs/JFXAlertsTest.kt<|end_filename|>
package ktfx.jfoenix.dialogs

import ktfx.dialogs.buttons
import com.hendraanggrian.ktfx.test.DialogShowingTest
import ktfx.callbackOf
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class JFXAlertsTest : DialogShowingTest() {

    @Test
    fun jfxAlert() {
        interact {
            assertEquals("Close", stage.jfxAlert<String>("Jfoenix alert", sampleGraphic) {
                setOnShown { close() }
                assertEquals("Jfoenix alert", title)
                assertEquals(sampleGraphic, graphic)
                buttons.close()
                resultConverter = callbackOf { it.text }
            }.get())
        }
    }
}

<|start_filename|>ktfx-commons/src/ktfx/collections/ObservableCollectionsSet.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ObservableCollectionsKt")
@file:OptIn(ExperimentalContracts::class)
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.collections

import javafx.collections.FXCollections
import javafx.collections.ObservableSet
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/**
 * Returns an empty read-only [ObservableSet].
 * @see emptySet
 */
inline fun <T> emptyObservableSet(): ObservableSet<T> = FXCollections.emptyObservableSet()

/**
 * Returns a new read-only [ObservableSet] of given elements.
 * @see setOf
 */
fun <T> observableSetOf(vararg elements: T): ObservableSet<T> =
    if (elements.isNotEmpty()) FXCollections.unmodifiableObservableSet(elements.toMutableObservableSet())
    else emptyObservableSet()

/**
 * Returns an empty read-only [ObservableSet].
 * @see setOf
 */
inline fun <T> observableSetOf(): ObservableSet<T> = emptyObservableSet()

/**
 * Returns an empty [ObservableSet].
 * @see mutableSetOf
 */
inline fun <T> mutableObservableSetOf(): ObservableSet<T> = FXCollections.observableSet()

/**
 * Returns a new [ObservableSet] with the given elements.
 * @see mutableSetOf
 */
fun <T> mutableObservableSetOf(vararg elements: T): ObservableSet<T> =
    if (elements.isEmpty()) mutableObservableSetOf() else FXCollections.observableSet(*elements)

/**
 * Returns a new read-only [ObservableSet] only of those given elements, that are not null.
 * @see setOfNotNull
 */
fun <T : Any> observableSetOfNotNull(vararg elements: T?): ObservableSet<T> =
    elements.filterNotNullTo(mutableObservableSetOf())

/**
 * Builds a new read-only [ObservableSet] by populating a [MutableSet]
 * using the given [builderAction] and returning a read-only set with the same elements.
 * @see buildSet
 */
@ExperimentalStdlibApi
inline fun <T> buildObservableSet(builderAction: MutableSet<T>.() -> Unit): Set<T> {
    contract { callsInPlace(builderAction, InvocationKind.EXACTLY_ONCE) }
    return buildSet(builderAction).toObservableSet()
}

/**
 * Returns an [ObservableSet] containing all elements.
 * @see Array.toSet
 */
fun <T> Array<out T>.toObservableSet(): ObservableSet<T> = when (size) {
    0 -> emptyObservableSet()
    else -> FXCollections.unmodifiableObservableSet(this.toMutableObservableSet())
}

/**
 * Returns a new [ObservableSet] filled with all elements of this array.
 * @see Array.toMutableSet
 */
inline fun <T> Array<out T>.toMutableObservableSet(): ObservableSet<T> = FXCollections.observableSet<T>(*this)

/**
 * Returns an [ObservableSet] containing all elements.
 * @see Iterable.toSet
 */
fun <T> Iterable<T>.toObservableSet(): ObservableSet<T> {
    if (this is Collection) {
        return when (size) {
            0 -> emptyObservableSet()
            else -> FXCollections.unmodifiableObservableSet(this.toMutableObservableSet())
        }
    }
    return toCollection(FXCollections.observableSet()).optimizeReadOnlySet()
}

/**
 * Returns a new [ObservableSet] filled with all elements of this collection.
 * @see Iterable.toMutableSet
 */
fun <T> Iterable<T>.toMutableObservableSet(): ObservableSet<T> = when (this) {
    is Set<T> -> FXCollections.observableSet(this)
    else -> toCollection(FXCollections.observableSet())
}

/**
 * Returns a [ObservableSet] containing all elements.
 * @see Sequence.toSet
 */
fun <T> Sequence<T>.toObservableSet(): ObservableSet<T> = toMutableObservableSet().optimizeReadOnlySet()

/**
 * Returns a new [ObservableSet] filled with all elements of this sequence.
 * @see Sequence.toMutableSet
 */
fun <T> Sequence<T>.toMutableObservableSet(): ObservableSet<T> = toCollection(FXCollections.observableSet())


<|start_filename|>ktfx-commons/tests/src/ktfx/bindings/BooleanValueBindingTest.kt<|end_filename|>
package ktfx.bindings

import ktfx.booleanPropertyOf
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class BooleanValueBindingTest {

    @Test
    fun and() {
        assertFalse((booleanPropertyOf(false) and booleanPropertyOf(false)).value)
        assertFalse((booleanPropertyOf(false) and booleanPropertyOf(true)).value)
        assertTrue((booleanPropertyOf(true) and booleanPropertyOf(true)).value)
    }

    @Test
    fun or() {
        assertFalse((booleanPropertyOf(false) or booleanPropertyOf(false)).value)
        assertTrue((booleanPropertyOf(false) or booleanPropertyOf(true)).value)
        assertTrue((booleanPropertyOf(true) or booleanPropertyOf(true)).value)
    }

    @Test
    fun eq() {
        assertTrue((booleanPropertyOf(false) eq booleanPropertyOf(false)).value)
        assertFalse((booleanPropertyOf(false) eq booleanPropertyOf(true)).value)
        assertTrue((booleanPropertyOf(true) eq booleanPropertyOf(true)).value)
    }

    @Test
    fun neq() {
        assertFalse((booleanPropertyOf(false) neq booleanPropertyOf(false)).value)
        assertTrue((booleanPropertyOf(false) neq booleanPropertyOf(true)).value)
        assertFalse((booleanPropertyOf(true) neq booleanPropertyOf(true)).value)
    }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/ToolBarTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.ToolBar
import com.hendraanggrian.ktfx.test.LayoutsTest

class ToolBarTest : LayoutsTest<KtfxPane, ToolBar>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = toolBar { }
    override fun KtfxPane.child2() = toolBar()
    override fun KtfxPane.child3() = toolBar { }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/ContextMenuTest.kt<|end_filename|>
package ktfx.listeners

import javafx.event.ActionEvent
import javafx.scene.control.ContextMenu
import com.hendraanggrian.ktfx.test.BaseContextMenuTest

class ContextMenuTest : BaseContextMenuTest() {

    override fun ContextMenu.callOnAction(action: (ActionEvent) -> Unit) = onAction(action)
}

<|start_filename|>ktfx-commons/tests/src/ktfx/controls/BackgroundsTest.kt<|end_filename|>
package ktfx.controls

import com.hendraanggrian.ktfx.test.SampleImage
import com.hendraanggrian.ktfx.test.initToolkit
import javafx.geometry.Insets
import javafx.scene.layout.BackgroundPosition
import javafx.scene.layout.BackgroundRepeat
import javafx.scene.layout.BackgroundSize
import javafx.scene.layout.CornerRadii
import javafx.scene.layout.Region
import javafx.scene.paint.Color
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals

class BackgroundsTest {
    private lateinit var region: Region

    @BeforeTest
    fun start() {
        initToolkit()
        region = Region()
    }

    @Test
    fun multiple() {
        region.background {
            fill { }
            image(SampleImage()) { }
        }
        assertEquals(1, region.background.fills.size)
        assertEquals(1, region.background.images.size)
    }

    @Test
    fun singleFill() {
        region.backgroundFill {
            fill = Color.RED
            radii = CornerRadii(5.0)
            insets = Insets(10.0)
        }
        val fill = region.background.fills.first()
        assertEquals(Color.RED, fill.fill)
        assertEquals(5.0, fill.radii.bottomLeftHorizontalRadius)
        assertEquals(Insets(10.0), fill.insets)
    }

    @Test
    fun singleImage() {
        val sample = SampleImage()
        val backgroundSize = BackgroundSize(1.0, 2.0, true, true, true, true)
        region.backgroundImage(sample) {
            repeat = BackgroundRepeat.ROUND
            position = BackgroundPosition.CENTER
            size = backgroundSize
        }
        region.background.images.first().let {
            assertEquals(sample, it.image)
            assertEquals(BackgroundRepeat.ROUND, it.repeatX)
            assertEquals(BackgroundRepeat.ROUND, it.repeatY)
            assertEquals(BackgroundPosition.CENTER, it.position)
            assertEquals(backgroundSize, it.size)
        }
    }
}


<|start_filename|>ktfx-layouts/src/ktfx/layouts/_MoveTo.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.shape.MoveTo
import kotlin.Double
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [MoveTo] to this manager.
 *
 * @return the control added.
 */
public fun PathElementManager.moveTo(x: Double = 0.0, y: Double = 0.0): MoveTo = moveTo(
    x = x,
    y =
    y
) { }

/**
 * Create a [MoveTo] with configuration block.
 * @param configuration the configuration block.
 *
 * @return the control created.
 */
public inline fun moveTo(
    x: Double = 0.0,
    y: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker MoveTo).() -> Unit
): MoveTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = MoveTo(x, y)
    child.configuration()
    return child
}

/**
 * Add a [MoveTo] with configuration block to this manager.
 * @param configuration the configuration block.
 *
 * @return the control added.
 */
public inline fun PathElementManager.moveTo(
    x: Double = 0.0,
    y: Double = 0.0,
    configuration: (@KtfxLayoutDslMarker MoveTo).() -> Unit
): MoveTo {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = MoveTo(x, y)
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-listeners/tests/src/javafx/beans/ObservableTest.kt<|end_filename|>
package ktfx.listeners

import javafx.beans.Observable
import com.hendraanggrian.ktfx.test.BaseObservableTest

class ObservableTest : BaseObservableTest() {

    override fun Observable.callListener(action: (Observable) -> Unit) {
        listener(action)
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/src/ktfx/jfoenix/layouts/_JFXMasonryPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXMasonryPane
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import kotlin.String
import kotlin.Unit
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind.EXACTLY_ONCE
import kotlin.contracts.contract
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * Add a [JFXMasonryPane] to this manager.
 *
 * @return the control added.
 */
public fun NodeManager.jfxMasonryPane(): JFXMasonryPane = jfxMasonryPane() { }

/**
 * Create a [JFXMasonryPane] with configuration block.
 *
 * @param configuration the configuration block.
 * @return the control created.
 */
public inline fun jfxMasonryPane(
    configuration: (@KtfxLayoutDslMarker KtfxJFXMasonryPane).() ->
    Unit
): JFXMasonryPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXMasonryPane()
    child.configuration()
    return child
}

/**
 * Add a [JFXMasonryPane] with configuration block to this manager.
 *
 * @param configuration the configuration block.
 * @return the control added.
 */
public inline fun NodeManager.jfxMasonryPane(
    configuration: (
        @KtfxLayoutDslMarker
        KtfxJFXMasonryPane
    ).() -> Unit
): JFXMasonryPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXMasonryPane()
    child.configuration()
    return addChild(child)
}

/**
 * Create a styled [JFXMasonryPane].
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control created.
 */
public fun styledJFXMasonryPane(vararg styleClass: String, id: String? = null): JFXMasonryPane =
    styledJFXMasonryPane(styleClass = *styleClass, id = id) { }

/**
 * Add a styled [JFXMasonryPane] to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @return the styled control added.
 */
public fun NodeManager.styledJFXMasonryPane(vararg styleClass: String, id: String? = null):
    JFXMasonryPane = styledJFXMasonryPane(styleClass = *styleClass, id = id) { }

/**
 * Create a styled [JFXMasonryPane] with configuration block.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control created.
 */
public inline fun styledJFXMasonryPane(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxJFXMasonryPane).() -> Unit
): JFXMasonryPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXMasonryPane()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return child
}

/**
 * Add a styled [JFXMasonryPane] with configuration block to this manager.
 *
 * @param styleClass the CSS style class.
 * @param id the CSS id.
 * @param configuration the configuration block.
 * @return the styled control added.
 */
public inline fun NodeManager.styledJFXMasonryPane(
    vararg styleClass: String,
    id: String? = null,
    configuration: (@KtfxLayoutDslMarker KtfxJFXMasonryPane).() -> Unit
): JFXMasonryPane {
    contract { callsInPlace(configuration, EXACTLY_ONCE) }
    val child = KtfxJFXMasonryPane()
    child.styleClass += styleClass
    child.id = id
    child.configuration()
    return addChild(child)
}


<|start_filename|>ktfx-listeners/src/ktfx/listeners/_Node.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxListenersKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.listeners

import javafx.scene.Node
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent
import kotlin.Suppress
import kotlin.Unit
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Node.setOnDragEntered
 */
public inline fun Node.onDragEntered(noinline action: (DragEvent) -> Unit) {
    return setOnDragEntered(action)
}

/**
 * @see Node.setOnDragExited
 */
public inline fun Node.onDragExited(noinline action: (DragEvent) -> Unit) {
    return setOnDragExited(action)
}

/**
 * @see Node.setOnDragOver
 */
public inline fun Node.onDragOver(noinline action: (DragEvent) -> Unit) {
    return setOnDragOver(action)
}

/**
 * @see Node.setOnDragDropped
 */
public inline fun Node.onDragDropped(noinline action: (DragEvent) -> Unit) {
    return setOnDragDropped(action)
}

/**
 * @see Node.setOnDragDone
 */
public inline fun Node.onDragDone(noinline action: (DragEvent) -> Unit) {
    return setOnDragDone(action)
}

/**
 * @see Node.setOnContextMenuRequested
 */
public inline fun Node.onContextMenuRequested(noinline action: (ContextMenuEvent) -> Unit) {
    return setOnContextMenuRequested(action)
}

/**
 * @see Node.setOnMouseClicked
 */
public inline fun Node.onMouseClicked(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseClicked(action)
}

/**
 * @see Node.setOnMouseDragged
 */
public inline fun Node.onMouseDragged(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseDragged(action)
}

/**
 * @see Node.setOnMouseEntered
 */
public inline fun Node.onMouseEntered(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseEntered(action)
}

/**
 * @see Node.setOnMouseExited
 */
public inline fun Node.onMouseExited(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseExited(action)
}

/**
 * @see Node.setOnMouseMoved
 */
public inline fun Node.onMouseMoved(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseMoved(action)
}

/**
 * @see Node.setOnMousePressed
 */
public inline fun Node.onMousePressed(noinline action: (MouseEvent) -> Unit) {
    return setOnMousePressed(action)
}

/**
 * @see Node.setOnMouseReleased
 */
public inline fun Node.onMouseReleased(noinline action: (MouseEvent) -> Unit) {
    return setOnMouseReleased(action)
}

/**
 * @see Node.setOnDragDetected
 */
public inline fun Node.onDragDetected(noinline action: (MouseEvent) -> Unit) {
    return setOnDragDetected(action)
}

/**
 * @see Node.setOnMouseDragOver
 */
public inline fun Node.onMouseDragOver(noinline action: (MouseDragEvent) -> Unit) {
    return setOnMouseDragOver(action)
}

/**
 * @see Node.setOnMouseDragReleased
 */
public inline fun Node.onMouseDragReleased(noinline action: (MouseDragEvent) -> Unit) {
    return setOnMouseDragReleased(action)
}

/**
 * @see Node.setOnMouseDragEntered
 */
public inline fun Node.onMouseDragEntered(noinline action: (MouseDragEvent) -> Unit) {
    return setOnMouseDragEntered(action)
}

/**
 * @see Node.setOnMouseDragExited
 */
public inline fun Node.onMouseDragExited(noinline action: (MouseDragEvent) -> Unit) {
    return setOnMouseDragExited(action)
}

/**
 * @see Node.setOnScrollStarted
 */
public inline fun Node.onScrollStarted(noinline action: (ScrollEvent) -> Unit) {
    return setOnScrollStarted(action)
}

/**
 * @see Node.setOnScroll
 */
public inline fun Node.onScroll(noinline action: (ScrollEvent) -> Unit) {
    return setOnScroll(action)
}

/**
 * @see Node.setOnScrollFinished
 */
public inline fun Node.onScrollFinished(noinline action: (ScrollEvent) -> Unit) {
    return setOnScrollFinished(action)
}

/**
 * @see Node.setOnRotationStarted
 */
public inline fun Node.onRotationStarted(noinline action: (RotateEvent) -> Unit) {
    return setOnRotationStarted(action)
}

/**
 * @see Node.setOnRotate
 */
public inline fun Node.onRotate(noinline action: (RotateEvent) -> Unit) {
    return setOnRotate(action)
}

/**
 * @see Node.setOnRotationFinished
 */
public inline fun Node.onRotationFinished(noinline action: (RotateEvent) -> Unit) {
    return setOnRotationFinished(action)
}

/**
 * @see Node.setOnZoomStarted
 */
public inline fun Node.onZoomStarted(noinline action: (ZoomEvent) -> Unit) {
    return setOnZoomStarted(action)
}

/**
 * @see Node.setOnZoom
 */
public inline fun Node.onZoom(noinline action: (ZoomEvent) -> Unit) {
    return setOnZoom(action)
}

/**
 * @see Node.setOnZoomFinished
 */
public inline fun Node.onZoomFinished(noinline action: (ZoomEvent) -> Unit) {
    return setOnZoomFinished(action)
}

/**
 * @see Node.setOnSwipeUp
 */
public inline fun Node.onSwipeUp(noinline action: (SwipeEvent) -> Unit) {
    return setOnSwipeUp(action)
}

/**
 * @see Node.setOnSwipeDown
 */
public inline fun Node.onSwipeDown(noinline action: (SwipeEvent) -> Unit) {
    return setOnSwipeDown(action)
}

/**
 * @see Node.setOnSwipeLeft
 */
public inline fun Node.onSwipeLeft(noinline action: (SwipeEvent) -> Unit) {
    return setOnSwipeLeft(action)
}

/**
 * @see Node.setOnSwipeRight
 */
public inline fun Node.onSwipeRight(noinline action: (SwipeEvent) -> Unit) {
    return setOnSwipeRight(action)
}

/**
 * @see Node.setOnTouchPressed
 */
public inline fun Node.onTouchPressed(noinline action: (TouchEvent) -> Unit) {
    return setOnTouchPressed(action)
}

/**
 * @see Node.setOnTouchMoved
 */
public inline fun Node.onTouchMoved(noinline action: (TouchEvent) -> Unit) {
    return setOnTouchMoved(action)
}

/**
 * @see Node.setOnTouchReleased
 */
public inline fun Node.onTouchReleased(noinline action: (TouchEvent) -> Unit) {
    return setOnTouchReleased(action)
}

/**
 * @see Node.setOnTouchStationary
 */
public inline fun Node.onTouchStationary(noinline action: (TouchEvent) -> Unit) {
    return setOnTouchStationary(action)
}

/**
 * @see Node.setOnKeyPressed
 */
public inline fun Node.onKeyPressed(noinline action: (KeyEvent) -> Unit) {
    return setOnKeyPressed(action)
}

/**
 * @see Node.setOnKeyReleased
 */
public inline fun Node.onKeyReleased(noinline action: (KeyEvent) -> Unit) {
    return setOnKeyReleased(action)
}

/**
 * @see Node.setOnKeyTyped
 */
public inline fun Node.onKeyTyped(noinline action: (KeyEvent) -> Unit) {
    return setOnKeyTyped(action)
}

/**
 * @see Node.setOnInputMethodTextChanged
 */
public inline fun Node.onInputMethodTextChanged(noinline action: (InputMethodEvent) -> Unit) {
    return setOnInputMethodTextChanged(action)
}


<|start_filename|>testing/listeners-coroutines/src/javafx/concurrent/BaseTaskTest.kt<|end_filename|>
package com.hendraanggrian.ktfx.test

import javafx.concurrent.Task
import javafx.concurrent.WorkerStateEvent
import kotlin.test.Test
import kotlin.test.assertEquals

abstract class BaseTaskTest {

    class HelloWorldTask : Task<String>() {
        override fun call() = "Hello world"
    }

    private val task = HelloWorldTask()

    abstract fun <E> Task<E>.callOnScheduled(action: (WorkerStateEvent) -> Unit)
    abstract fun <E> Task<E>.callOnRunning(action: (WorkerStateEvent) -> Unit)
    abstract fun <E> Task<E>.callOnSucceeded(action: (WorkerStateEvent) -> Unit)
    abstract fun <E> Task<E>.callOnCancelled(action: (WorkerStateEvent) -> Unit)
    abstract fun <E> Task<E>.callOnFailed(action: (WorkerStateEvent) -> Unit)

    @Test
    fun onScheduled() {
        task.callOnScheduled {
            assertEquals(task, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_SCHEDULED, it.eventType)
        }
        task.onScheduled.handle(WorkerStateEvent(task, WorkerStateEvent.WORKER_STATE_SCHEDULED))
    }

    @Test
    fun onRunning() {
        task.callOnRunning {
            assertEquals(task, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_RUNNING, it.eventType)
        }
        task.onRunning.handle(WorkerStateEvent(task, WorkerStateEvent.WORKER_STATE_RUNNING))
    }

    @Test
    fun onSucceeded() {
        task.callOnSucceeded {
            assertEquals(task, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_SUCCEEDED, it.eventType)
        }
        task.onSucceeded.handle(WorkerStateEvent(task, WorkerStateEvent.WORKER_STATE_SUCCEEDED))
    }

    @Test
    fun onCancelled() {
        task.callOnCancelled {
            assertEquals(task, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_CANCELLED, it.eventType)
        }
        task.onCancelled.handle(WorkerStateEvent(task, WorkerStateEvent.WORKER_STATE_CANCELLED))
    }

    @Test
    fun onFailed() {
        task.callOnFailed {
            assertEquals(task, it.source)
            assertEquals(WorkerStateEvent.WORKER_STATE_FAILED, it.eventType)
        }
        task.onFailed.handle(WorkerStateEvent(task, WorkerStateEvent.WORKER_STATE_FAILED))
    }
}

<|start_filename|>thirdparty/jfoenix-coroutines/src/ktfx/jfoenix/coroutines/_JFXAnimationTimer.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixCoroutinesKt")

package ktfx.jfoenix.coroutines

import com.jfoenix.transitions.JFXAnimationTimer
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see JFXAnimationTimer.setOnFinished
 */
public fun JFXAnimationTimer.onFinished(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.() -> Unit
) {
    return setOnFinished { GlobalScope.launch(context) { action() } }
}


<|start_filename|>thirdparty/controlsfx-coroutines/src/ktfx/controlsfx/coroutines/_NotificationPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxCoroutinesKt")

package ktfx.controlsfx.coroutines

import javafx.event.Event
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import org.controlsfx.control.NotificationPane
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see NotificationPane.setOnShowing
 */
public fun NotificationPane.onShowing(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(Event) -> Unit
) {
    return setOnShowing { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see NotificationPane.setOnShown
 */
public fun NotificationPane.onShown(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnShown { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see NotificationPane.setOnHiding
 */
public fun NotificationPane.onHiding(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnHiding { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see NotificationPane.setOnHidden
 */
public fun NotificationPane.onHidden(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(Event) -> Unit
) {
    return setOnHidden { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_Task.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.concurrent.Task
import javafx.concurrent.WorkerStateEvent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Task.setOnScheduled
 */
public fun Task<*>.onScheduled(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnScheduled { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Task.setOnRunning
 */
public fun Task<*>.onRunning(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnRunning { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Task.setOnSucceeded
 */
public fun Task<*>.onSucceeded(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnSucceeded { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Task.setOnCancelled
 */
public fun Task<*>.onCancelled(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnCancelled { event -> GlobalScope.launch(context) { action(event) } }
}

/**
 * @see Task.setOnFailed
 */
public fun Task<*>.onFailed(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.(WorkerStateEvent) -> Unit
) {
    return setOnFailed { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-commons/src/ktfx/bindings/BindingsLong.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("BindingsKt")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.bindings

import javafx.beans.Observable
import javafx.beans.binding.Bindings
import javafx.beans.binding.LongBinding
import javafx.beans.value.ObservableBooleanValue
import javafx.beans.value.ObservableDoubleValue
import javafx.beans.value.ObservableFloatValue
import javafx.beans.value.ObservableIntegerValue
import javafx.beans.value.ObservableLongValue
import javafx.beans.value.ObservableObjectValue
import javafx.collections.ObservableList
import javafx.collections.ObservableMap
import javafx.collections.ObservableSet
import ktfx.collections.observableListOf
import ktfx.collections.toObservableList
import java.util.concurrent.Callable

/** Create a [LongBinding] with multiple [Observable] dependencies. */
inline fun longBindingOf(vararg dependencies: Observable, noinline valueProvider: () -> Long): LongBinding =
    Bindings.createLongBinding(Callable(valueProvider), *dependencies)

/** Create a [LongBinding] with multiple [Observable] dependencies using collection. */
fun longBindingOf(dependencies: Collection<Observable>, valueProvider: () -> Long): LongBinding =
    longBindingOf(*dependencies.toTypedArray(), valueProvider = valueProvider)

/** Create an [LongBinding] with single [ObservableList] dependency. */
fun <E> ObservableList<E>.asLong(valueProvider: (List<E>) -> Long): LongBinding =
    object : LongBinding() {
        override fun dispose(): Unit = unbind(this@asLong)
        override fun computeValue(): Long = valueProvider(this@asLong)
        override fun getDependencies(): ObservableList<*> = this@asLong

        init {
            bind(this@asLong)
        }
    }

/** Create an [LongBinding] with single [ObservableSet] dependency. */
fun <E> ObservableSet<E>.asLong(valueProvider: (Set<E>) -> Long): LongBinding =
    object : LongBinding() {
        override fun dispose(): Unit = unbind(this@asLong)
        override fun computeValue(): Long = valueProvider(this@asLong)
        override fun getDependencies(): ObservableList<*> = this@asLong.toObservableList()

        init {
            bind(this@asLong)
        }
    }

/** Create an [LongBinding] with single [ObservableMap] dependency. */
fun <K, V> ObservableMap<K, V>.asLong(valueProvider: (Map<K, V>) -> Long): LongBinding =
    object : LongBinding() {
        override fun dispose(): Unit = unbind(this@asLong)
        override fun computeValue(): Long = valueProvider(this@asLong)
        override fun getDependencies(): ObservableList<*> = this@asLong.keys.toObservableList()

        init {
            bind(this@asLong)
        }
    }

/** Create a [LongBinding] with single [ObservableObjectValue] dependency. */
fun <V> ObservableObjectValue<V>.asLong(valueProvider: (V?) -> Long): LongBinding =
    object : LongBinding() {
        override fun dispose(): Unit = unbind(this@asLong)
        override fun computeValue(): Long = valueProvider(this@asLong.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asLong)

        init {
            bind(this@asLong)
        }
    }

/** Create a [LongBinding] with single [ObservableBooleanValue] dependency. */
fun ObservableBooleanValue.asLong(valueProvider: (Boolean) -> Long): LongBinding =
    object : LongBinding() {
        override fun dispose(): Unit = unbind(this@asLong)
        override fun computeValue(): Long = valueProvider(this@asLong.value)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asLong)

        init {
            bind(this@asLong)
        }
    }

/** Create a [LongBinding] with single [ObservableDoubleValue] dependency. */
fun ObservableDoubleValue.asLong(valueProvider: (Double) -> Long): LongBinding =
    object : LongBinding() {
        override fun dispose(): Unit = unbind(this@asLong)
        override fun computeValue(): Long = valueProvider(this@asLong.value as Double)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asLong)

        init {
            bind(this@asLong)
        }
    }

/** Create a [LongBinding] with single [ObservableFloatValue] dependency. */
fun ObservableFloatValue.asLong(valueProvider: (Float) -> Long): LongBinding =
    object : LongBinding() {
        override fun dispose(): Unit = unbind(this@asLong)
        override fun computeValue(): Long = valueProvider(this@asLong.value as Float)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asLong)

        init {
            bind(this@asLong)
        }
    }

/** Create a [LongBinding] with single [ObservableIntegerValue] dependency. */
fun ObservableIntegerValue.asLong(valueProvider: (Int) -> Long): LongBinding =
    object : LongBinding() {
        override fun dispose(): Unit = unbind(this@asLong)
        override fun computeValue(): Long = valueProvider(this@asLong.value as Int)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asLong)

        init {
            bind(this@asLong)
        }
    }

/** Create a [LongBinding] with single [ObservableLongValue] dependency. */
fun ObservableLongValue.asLong(valueProvider: (Long) -> Long): LongBinding =
    object : LongBinding() {
        override fun dispose(): Unit = unbind(this@asLong)
        override fun computeValue(): Long = valueProvider(this@asLong.value as Long)
        override fun getDependencies(): ObservableList<*> = observableListOf(this@asLong)

        init {
            bind(this@asLong)
        }
    }


<|start_filename|>testing/listeners-coroutines-jfoenix/src/com/jfoenix/transitions/BaseJFXAnimationTimerTest.kt<|end_filename|>
package ktfx.jfoenix.test

import com.jfoenix.transitions.JFXAnimationTimer
import com.hendraanggrian.ktfx.test.initToolkit
import kotlin.test.BeforeTest
import kotlin.test.Test

abstract class BaseJFXAnimationTimerTest {
    private lateinit var timer: JFXAnimationTimer

    abstract fun JFXAnimationTimer.callOnFinished(action: () -> Unit)

    @BeforeTest fun start() {
        initToolkit()
        timer = JFXAnimationTimer()
    }

    @Test
    fun onFinished() {
        timer.callOnFinished { }
    }
}

<|start_filename|>thirdparty/jfoenix-layouts/src/com/jfoenix/controls/KtfxJFXScrollPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXScrollPane
import javafx.scene.Node
import ktfx.layouts.NodeManager
import kotlin.contracts.ExperimentalContracts

/**
 * [JFXScrollPane] with dynamic-layout dsl support.
 * Invoking dsl will only set its content.
 */
open class KtfxJFXScrollPane : JFXScrollPane(), NodeManager {

    final override fun <C : Node> addChild(child: C): C = child.also { content = it }
}


<|start_filename|>thirdparty/jfoenix-layouts/src/com/jfoenix/controls/JFXScrollPane.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("JFoenixLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXScrollPane
import javafx.scene.Node
import ktfx.layouts.KtfxLayoutDslMarker
import ktfx.layouts.NodeManager
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

@PublishedApi
internal class NodeManagerImpl : NodeManager {
    val children: MutableList<Node> = mutableListOf()

    override fun <C : Node> addChild(child: C): C = child.also { children += it }
}

/**
 * Configure [JFXScrollPane] top bar.
 * @param configuration the configuration block.
 */
inline fun JFXScrollPane.topBar(configuration: (@KtfxLayoutDslMarker NodeManager).() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    topBar.children.addAll(NodeManagerImpl().apply(configuration).children)
}

/**
 * Configure [JFXScrollPane] mid bar.
 * @param configuration the configuration block.
 */
inline fun JFXScrollPane.midBar(configuration: (@KtfxLayoutDslMarker NodeManager).() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    midBar.children.addAll(NodeManagerImpl().apply(configuration).children)
}

/**
 * Configure [JFXScrollPane] bottom bar.
 * @param configuration the configuration block.
 */
inline fun JFXScrollPane.bottomBar(configuration: (@KtfxLayoutDslMarker NodeManager).() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    bottomBar.children.addAll(NodeManagerImpl().apply(configuration).children)
}

/**
 * Configure [JFXScrollPane] main header.
 * @param configuration the configuration block.
 */
inline fun JFXScrollPane.mainHeader(configuration: (@KtfxLayoutDslMarker NodeManager).() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    mainHeader.children.addAll(NodeManagerImpl().apply(configuration).children)
}

/**
 * Configure [JFXScrollPane] condensed header.
 * @param configuration the configuration block.
 */
inline fun JFXScrollPane.condensedHeader(configuration: (@KtfxLayoutDslMarker NodeManager).() -> Unit) {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    condensedHeader.children.addAll(NodeManagerImpl().apply(configuration).children)
}


<|start_filename|>ktfx-coroutines/tests/src/javafx/concurrent/ServiceTest.kt<|end_filename|>
package ktfx.coroutines

import javafx.concurrent.Service
import javafx.concurrent.WorkerStateEvent
import kotlinx.coroutines.Dispatchers
import com.hendraanggrian.ktfx.test.BaseServiceTest

class ServiceTest : BaseServiceTest() {

    override fun <E> Service<E>.callOnReady(action: (WorkerStateEvent) -> Unit) =
        onReady(Dispatchers.Unconfined) { action(it) }

    override fun <E> Service<E>.callOnScheduled(action: (WorkerStateEvent) -> Unit) =
        onScheduled(Dispatchers.Unconfined) { action(it) }

    override fun <E> Service<E>.callOnRunning(action: (WorkerStateEvent) -> Unit) =
        onRunning(Dispatchers.Unconfined) { action(it) }

    override fun <E> Service<E>.callOnSucceeded(action: (WorkerStateEvent) -> Unit) =
        onSucceeded(Dispatchers.Unconfined) { action(it) }

    override fun <E> Service<E>.callOnCancelled(action: (WorkerStateEvent) -> Unit) =
        onCancelled(Dispatchers.Unconfined) { action(it) }

    override fun <E> Service<E>.callOnFailed(action: (WorkerStateEvent) -> Unit) =
        onFailed(Dispatchers.Unconfined) { action(it) }
}

<|start_filename|>thirdparty/jfoenix-layouts/tests/src/com/jfoenix/controls/JFXProgressBarTest.kt<|end_filename|>
package ktfx.jfoenix.layouts

import com.jfoenix.controls.JFXProgressBar
import javafx.scene.control.ProgressBar
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class JFXProgressBarTest : LayoutsTest<KtfxPane, JFXProgressBar>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = jfxProgressBar { }
    override fun KtfxPane.child2() = jfxProgressBar()
    override fun KtfxPane.child3() = jfxProgressBar { }

    override fun JFXProgressBar.testDefaultValues() {
        assertEquals(ProgressBar.INDETERMINATE_PROGRESS, progress)
    }
}

<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/TextFieldTest.kt<|end_filename|>
package ktfx.listeners

import javafx.event.ActionEvent
import javafx.scene.control.TextField
import com.hendraanggrian.ktfx.test.BaseTextFieldTest

class TextFieldTest : BaseTextFieldTest() {

    override fun TextField.callOnAction(action: (ActionEvent) -> Unit) = onAction(action)
}

<|start_filename|>ktfx-commons/src/ktfx/cells/KtfxCell.kt<|end_filename|>
package ktfx.cells

/** Defines a lifecycle of custom cell/row. */
internal interface KtfxCell<out T> {

    /** Called when cell is on editing mode. */
    fun onEditStart(action: () -> Unit)

    /** Called when cell edit is being committed. */
    fun onEditCommit(action: (T?) -> Unit)

    /** Called when cell edit is canceled. */
    fun onEditCancel(action: () -> Unit)

    /** Called when cell item is updating. */
    fun onUpdate(action: (T?, empty: Boolean) -> Unit)
}


<|start_filename|>thirdparty/controlsfx-coroutines/src/ktfx/controlsfx/coroutines/_BreadCrumbBar.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("ControlsFxCoroutinesKt")

package ktfx.controlsfx.coroutines

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import org.controlsfx.control.BreadCrumbBar
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see BreadCrumbBar.setOnCrumbAction
 */
public fun <T> BreadCrumbBar<T>.onCrumbAction(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend CoroutineScope.(BreadCrumbBar.BreadCrumbActionEvent<T>) -> Unit
) {
    return setOnCrumbAction { event -> GlobalScope.launch(context) { action(event) } }
}


<|start_filename|>ktfx-commons/tests/src/ktfx/PairTest.kt<|end_filename|>
package ktfx

import javafx.util.Pair
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class PairTest {

    @Test
    fun toKotlinPair() {
        val (s, i) = Pair("Hello", 123).toKotlinPair()
        assertEquals("Hello", s)
        assertEquals(123, i)

        val (n1, n2) = Pair(null, null).toKotlinPair()
        assertNull(n1)
        assertNull(n2)
    }

    @Test
    fun toFxPair() {
        val (s, i) = kotlin.Pair("Hello", 123).toFxPair()
        assertEquals("Hello", s)
        assertEquals(123, i)

        val (n1, n2) = kotlin.Pair(null, null).toFxPair()
        assertNull(n1)
        assertNull(n2)
    }
}


<|start_filename|>ktfx-commons/src/ktfx/dialogs/Selectors.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.dialogs

import javafx.scene.Node
import javafx.scene.control.ChoiceDialog
import javafx.scene.image.ImageView
import java.util.Optional

/**
 * Show a selector with title and graphic.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param items selection choices.
 * @param prefill default choice.
 * @param dialogAction custom dialog action.
 * @return selected item.
 */
fun <T> selector(
    title: String? = null,
    graphic: Node? = null,
    items: Collection<T>? = null,
    prefill: T? = null,
    dialogAction: (ChoiceDialog<T>.() -> Unit)? = null
): Optional<T> = ChoiceDialog<T>(prefill, items).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    dialogAction?.invoke(dialog)
}.showAndWait()

/**
 * Show a selector.
 * @param items selection choices.
 * @param prefill default choice.
 * @param dialogAction custom dialog action.
 * @return selected item.
 */
inline fun <T> selector(
    items: Collection<T>? = null,
    prefill: T? = null,
    noinline dialogAction: (ChoiceDialog<T>.() -> Unit)? = null
): Optional<T> = selector(null, null, items, prefill, dialogAction)

/**
 * Show a selector with title and graphic.
 * @param title title of the dialog.
 * @param graphic node to be displayed in header.
 * @param items selection choices.
 * @param prefill default choice.
 * @param dialogAction custom dialog action.
 * @return selected item.
 */
fun <T> selector(
    title: String? = null,
    graphic: Node? = null,
    vararg items: T,
    prefill: T? = null,
    dialogAction: (ChoiceDialog<T>.() -> Unit)? = null
): Optional<T> = ChoiceDialog<T>(prefill, *items).also { dialog ->
    if (title != null) dialog.headerTitle = title
    when {
        graphic is ImageView -> dialog.graphicIcon = graphic
        graphic != null -> dialog.graphic = graphic
    }
    dialogAction?.invoke(dialog)
}.showAndWait()

/**
 * Show a selector.
 * @param items selection choices.
 * @param prefill default choice.
 * @param dialogAction custom dialog action.
 * @return selected item.
 */
inline fun <T> selector(
    vararg items: T,
    prefill: T? = null,
    noinline dialogAction: (ChoiceDialog<T>.() -> Unit)? = null
): Optional<T> = selector(null, null, *items, prefill = prefill, dialogAction = dialogAction)


<|start_filename|>ktfx-commons/tests/src/ktfx/print/PrinterTest.kt<|end_filename|>
package ktfx.print

import javafx.print.Printer
import kotlin.test.Test
import kotlin.test.assertEquals

class PrinterTest {

    @Test
    fun createJob() {
        Printer.getDefaultPrinter()?.run {
            val job = createJob {
                copies = 2
                setPageRanges(1 untilPage 3)
            }
            assertEquals(2, job.jobSettings.copies)
            assertEquals(1, job.jobSettings.pageRanges.first().startPage)
            assertEquals(3, job.jobSettings.pageRanges.first().endPage)
        }
    }
}


<|start_filename|>ktfx-commons/src/ktfx/cells/TreeCells.kt<|end_filename|>
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.cells

import javafx.beans.value.ObservableValue
import javafx.collections.ObservableList
import javafx.scene.control.TreeCell
import javafx.scene.control.TreeItem
import javafx.scene.control.TreeView
import javafx.scene.control.cell.CheckBoxTreeCell
import javafx.scene.control.cell.ChoiceBoxTreeCell
import javafx.scene.control.cell.ComboBoxTreeCell
import javafx.scene.control.cell.TextFieldTreeCell
import javafx.util.StringConverter

/**
 * Sets a [CheckBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 */
inline fun <T> TreeView<T>.checkBoxCellFactory(): Unit =
    setCellFactory(CheckBoxTreeCell.forTreeView())

/**
 * Sets a [CheckBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param selectedPropertyProvider A provider that, given an object from `TreeItem<T>`,
 *  will return an `ObservableValue<Boolean>` that represents whether the given item is selected or not.
 */
inline fun <T> TreeView<T>.checkBoxCellFactory(
    noinline selectedPropertyProvider: (TreeItem<T>) -> ObservableValue<Boolean>
): Unit = setCellFactory(CheckBoxTreeCell.forTreeView(selectedPropertyProvider))

/**
 * Sets a [CheckBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param selectedPropertyProvider A provider that, given an object from `TreeItem<T>`,
 *  will return an `ObservableValue<Boolean>` that represents whether the given item is selected or not.
 */
inline fun <T> TreeView<T>.checkBoxCellFactory(
    converter: StringConverter<TreeItem<T>>,
    noinline selectedPropertyProvider: (TreeItem<T>) -> ObservableValue<Boolean>
): Unit = setCellFactory(CheckBoxTreeCell.forTreeView(selectedPropertyProvider, converter))

/**
 * Sets a [ChoiceBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <T> TreeView<T>.choiceBoxCellFactory(
    vararg items: T
): Unit = setCellFactory(ChoiceBoxTreeCell.forTreeView(*items))

/**
 * Sets a [ChoiceBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <T> TreeView<T>.choiceBoxCellFactory(
    converter: StringConverter<T>,
    vararg items: T
): Unit = setCellFactory(ChoiceBoxTreeCell.forTreeView(converter, *items))

/**
 * Sets a [ChoiceBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <T> TreeView<T>.choiceBoxCellFactory(
    items: ObservableList<T>
): Unit = setCellFactory(ChoiceBoxTreeCell.forTreeView(items))

/**
 * Sets a [ChoiceBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ChoiceBox] menu is showing.
 */
inline fun <T> TreeView<T>.choiceBoxCellFactory(
    converter: StringConverter<T>,
    items: ObservableList<T>
): Unit = setCellFactory(ChoiceBoxTreeCell.forTreeView(converter, items))

/**
 * Sets a [ComboBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <T> TreeView<T>.comboBoxCellFactory(
    vararg items: T
): Unit = setCellFactory(ComboBoxTreeCell.forTreeView(*items))

/**
 * Sets a [ComboBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <T> TreeView<T>.comboBoxCellFactory(
    converter: StringConverter<T>,
    vararg items: T
): Unit = setCellFactory(ComboBoxTreeCell.forTreeView(converter, *items))

/**
 * Sets a [ComboBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <T> TreeView<T>.comboBoxCellFactory(
    items: ObservableList<T>
): Unit = setCellFactory(ComboBoxTreeCell.forTreeView(items))

/**
 * Sets a [ComboBoxTreeCell] factory for use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 * @param items Zero or more items that will be shown to the user when the
 *  [javafx.scene.control.ComboBox] menu is showing.
 */
inline fun <T> TreeView<T>.comboBoxCellFactory(
    converter: StringConverter<T>,
    items: ObservableList<T>
): Unit = setCellFactory(ComboBoxTreeCell.forTreeView(converter, items))

/**
 * Sets a [TextFieldTreeCell] factory for use in this [TreeView].
 */
inline fun TreeView<String>.textFieldCellFactory(): Unit =
    setCellFactory(TextFieldTreeCell.forTreeView())

/**
 * Sets a [TextFieldTreeCell] factory for use in this [TreeView].
 * @param converter A string converter that, given an object of type T,
 *  will return a String that can be used to represent the object visually.
 */
inline fun <T> TreeView<T>.textFieldCellFactory(
    converter: StringConverter<T>
): Unit = setCellFactory(TextFieldTreeCell.forTreeView(converter))

/**
 * Sets a custom cell factory to use in this [TreeView].
 * @param T The type of the elements contained within the [TreeView].
 * @param configuration custom initialization block that configures [KtfxListCell].
 */
fun <T> TreeView<T>.cellFactory(
    configuration: KtfxTreeCell<T>.(TreeView<T>) -> Unit
): Unit = setCellFactory { KtfxTreeCell<T>().apply { configuration(it) } }

/** Custom [TreeCell] configurator class. */
class KtfxTreeCell<T> : TreeCell<T>(), KtfxCell<T> {
    private var onEditStart: (() -> Unit)? = null
    private var onEditCommit: ((T?) -> Unit)? = null
    private var onEditCancel: (() -> Unit)? = null
    private var onUpdate: ((T?, empty: Boolean) -> Unit)? = null

    override fun onEditStart(action: () -> Unit) {
        onEditStart = action
    }

    override fun startEdit() {
        super.startEdit()
        onEditStart?.invoke()
    }

    override fun onEditCommit(action: (T?) -> Unit) {
        onEditCommit = action
    }

    override fun commitEdit(newValue: T?) {
        super.commitEdit(newValue)
        onEditCommit?.invoke(newValue)
    }

    override fun onEditCancel(action: () -> Unit) {
        onEditCancel = action
    }

    override fun cancelEdit() {
        super.cancelEdit()
        onEditCancel?.invoke()
    }

    override fun onUpdate(action: (T?, empty: Boolean) -> Unit) {
        onUpdate = action
    }

    override fun updateItem(item: T?, empty: Boolean) {
        super.updateItem(item, empty)
        onUpdate?.invoke(item, empty)
    }
}


<|start_filename|>thirdparty/controlsfx-layouts/tests/src/org/controlsfx/control/PropertySheetTest.kt<|end_filename|>
package ktfx.controlsfx.layouts

import com.google.common.truth.Truth.assertThat
import ktfx.layouts.KtfxPane
import com.hendraanggrian.ktfx.test.LayoutsTest
import org.controlsfx.control.PropertySheet

class PropertySheetTest : LayoutsTest<KtfxPane, PropertySheet>() {

    override fun manager() = KtfxPane()
    override fun KtfxPane.childCount() = children.size
    override fun child1() = propertySheet { }
    override fun KtfxPane.child2() = propertySheet()
    override fun KtfxPane.child3() = propertySheet { }

    override fun PropertySheet.testDefaultValues() {
        assertThat(items).isEmpty()
    }
}

<|start_filename|>ktfx-layouts/tests/src/javafx/scene/control/TooltipTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.control.TableColumn
import javafx.util.Duration
import com.hendraanggrian.ktfx.test.initToolkit
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertNotNull

class TooltipTest {

    @BeforeTest fun start() = initToolkit()

    @Test
    fun node() {
        imageView {
            tooltip()
        }
        imageView {
            tooltip { }
        }
    }

    @Test
    fun control() {
        button {
            tooltip()
            assertNotNull(tooltip)
        }
        button {
            tooltip { }
            assertNotNull(tooltip)
        }
    }

    @Test
    fun tab() {
        tab {
            tooltip()
            assertNotNull(tooltip)
        }
        tab {
            tooltip { }
            assertNotNull(tooltip)
        }
    }

    @Test
    fun tableColumn() {
        val column1 = TableColumn<Duration, String>()
        column1.contextMenu()
        assertNotNull(column1.contextMenu)
        val column2 = TableColumn<Duration, String>()
        column2.contextMenu()
        assertNotNull(column2.contextMenu)
    }
}

<|start_filename|>thirdparty/controlsfx-commons/src/ktfx/controlsfx/text/Glyph.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("Glyphs")
@file:Suppress("NOTHING_TO_INLINE")

package ktfx.controlsfx.text

import javafx.scene.paint.Color
import org.controlsfx.glyphfont.Glyph

/**
 * Retrieve glyph by font name and glyph name using one string where font name an glyph name are separated by pipe.
 *
 * @receiver font name.
 * @param glyph name.
 */
inline infix fun String.glyph(glyph: String): Glyph = Glyph.create("$this|$glyph")

/** Sets the glyph icon font family. */
inline infix fun Glyph.family(family: String): Glyph = fontFamily(family)

/** Sets the glyph color. */
inline infix fun Glyph.color(color: Color): Glyph = color(color)

/** Sets glyph size. */
inline infix fun Glyph.size(size: Double): Glyph = size(size)

/** Sets glyph size using size factor based on default font size. */
inline infix fun Glyph.sizeFactor(factor: Int): Glyph = sizeFactor(factor)

/** Enables/disables the hover effect style. */
infix fun Glyph.useHoverEffect(useHoverEffect: Boolean): Glyph = when {
    useHoverEffect -> useHoverEffect()
    else -> apply { styleClass -= Glyph.STYLE_HOVER_EFFECT }
}

/** Enables/disables the gradient effect style. */
infix fun Glyph.useGradientEffect(useGradientEffect: Boolean): Glyph = when {
    useGradientEffect -> useGradientEffect()
    else -> apply { styleClass -= Glyph.STYLE_GRADIENT }
}


<|start_filename|>ktfx-layouts/tests/src/javafx/scene/shape/VLineToTest.kt<|end_filename|>
package ktfx.layouts

import javafx.scene.shape.VLineTo
import com.hendraanggrian.ktfx.test.LayoutsTest
import kotlin.test.assertEquals

class VLineToTest : LayoutsTest<KtfxPath, VLineTo>() {

    override fun manager() = KtfxPath()
    override fun KtfxPath.childCount() = elements.size
    override fun child1() = vlineTo { }
    override fun KtfxPath.child2() = vlineTo()
    override fun KtfxPath.child3() = vlineTo { }

    override fun VLineTo.testDefaultValues() {
        assertEquals(0.0, y)
    }
}

<|start_filename|>codegen/src/com/hendraanggrian/ktfx/codegen/listeners/Ktfx.kt<|end_filename|>
package com.hendraanggrian.ktfx.codegen.listeners

import com.hendraanggrian.kotlinpoet.parameterizedBy
import com.squareup.kotlinpoet.STAR
import com.hendraanggrian.ktfx.codegen.S
import com.hendraanggrian.ktfx.codegen.T
import javafx.animation.Animation
import javafx.concurrent.Service
import javafx.concurrent.Task
import javafx.concurrent.WorkerStateEvent
import javafx.event.ActionEvent
import javafx.event.Event
import javafx.geometry.Rectangle2D
import javafx.scene.Node
import javafx.scene.Scene
import javafx.scene.control.ButtonBase
import javafx.scene.control.ChoiceBox
import javafx.scene.control.ComboBoxBase
import javafx.scene.control.ContextMenu
import javafx.scene.control.Dialog
import javafx.scene.control.DialogEvent
import javafx.scene.control.ListView
import javafx.scene.control.Menu
import javafx.scene.control.MenuItem
import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.Tab
import javafx.scene.control.TableColumn
import javafx.scene.control.TableView
import javafx.scene.control.TextField
import javafx.scene.control.TreeTableColumn
import javafx.scene.control.TreeTableView
import javafx.scene.control.TreeView
import javafx.scene.input.ContextMenuEvent
import javafx.scene.input.DragEvent
import javafx.scene.input.InputMethodEvent
import javafx.scene.input.KeyEvent
import javafx.scene.input.MouseDragEvent
import javafx.scene.input.MouseEvent
import javafx.scene.input.RotateEvent
import javafx.scene.input.ScrollEvent
import javafx.scene.input.SwipeEvent
import javafx.scene.input.TouchEvent
import javafx.scene.input.ZoomEvent
import javafx.scene.media.Media
import javafx.scene.media.MediaErrorEvent
import javafx.scene.media.MediaMarkerEvent
import javafx.scene.media.MediaPlayer
import javafx.scene.media.MediaView
import javafx.scene.transform.Transform
import javafx.scene.transform.TransformChangedEvent
import javafx.scene.web.WebEngine
import javafx.scene.web.WebErrorEvent
import javafx.scene.web.WebEvent
import javafx.stage.PopupWindow
import javafx.stage.Window
import javafx.stage.WindowEvent

val ListenersFactory.Companion.JavaFx: ListenersFactory
    get() = ListenersFactory(
        "ktfx-listeners/src",
        "ktfx.listeners",
        "KtfxListenersKt"
    ).apply { initJavaFx() }

val CoroutinesFactory.Companion.JavaFx: CoroutinesFactory
    get() = CoroutinesFactory(
        "ktfx-coroutines/src",
        "ktfx.coroutines",
        "KtfxCoroutinesKt",
    ).apply { initJavaFx() }

private fun BaseListenersFactory.initJavaFx() {
    // javafx.animation
    Animation::class { "setOnFinished" { action<ActionEvent>() } }
    // javafx.concurrent
    (Service::class.parameterizedBy(STAR)) {
        "setOnReady" { action<WorkerStateEvent>() }
        "setOnScheduled" { action<WorkerStateEvent>() }
        "setOnRunning" { action<WorkerStateEvent>() }
        "setOnSucceeded" { action<WorkerStateEvent>() }
        "setOnCancelled" { action<WorkerStateEvent>() }
        "setOnFailed" { action<WorkerStateEvent>() }
    }
    (Task::class.parameterizedBy(STAR)) {
        "setOnScheduled" { action<WorkerStateEvent>() }
        "setOnRunning" { action<WorkerStateEvent>() }
        "setOnSucceeded" { action<WorkerStateEvent>() }
        "setOnCancelled" { action<WorkerStateEvent>() }
        "setOnFailed" { action<WorkerStateEvent>() }
    }
    // javafx.scene
    Node::class {
        "setOnDragEntered" { action<DragEvent>() }
        "setOnDragExited" { action<DragEvent>() }
        "setOnDragOver" { action<DragEvent>() }
        "setOnDragDropped" { action<DragEvent>() }
        "setOnDragDone" { action<DragEvent>() }
        "setOnContextMenuRequested" { action<ContextMenuEvent>() }
        "setOnMouseClicked" { action<MouseEvent>() }
        "setOnMouseDragged" { action<MouseEvent>() }
        "setOnMouseEntered" { action<MouseEvent>() }
        "setOnMouseExited" { action<MouseEvent>() }
        "setOnMouseMoved" { action<MouseEvent>() }
        "setOnMousePressed" { action<MouseEvent>() }
        "setOnMouseReleased" { action<MouseEvent>() }
        "setOnDragDetected" { action<MouseEvent>() }
        "setOnMouseDragOver" { action<MouseDragEvent>() }
        "setOnMouseDragReleased" { action<MouseDragEvent>() }
        "setOnMouseDragEntered" { action<MouseDragEvent>() }
        "setOnMouseDragExited" { action<MouseDragEvent>() }
        "setOnScrollStarted" { action<ScrollEvent>() }
        "setOnScroll" { action<ScrollEvent>() }
        "setOnScrollFinished" { action<ScrollEvent>() }
        "setOnRotationStarted" { action<RotateEvent>() }
        "setOnRotate" { action<RotateEvent>() }
        "setOnRotationFinished" { action<RotateEvent>() }
        "setOnZoomStarted" { action<ZoomEvent>() }
        "setOnZoom" { action<ZoomEvent>() }
        "setOnZoomFinished" { action<ZoomEvent>() }
        "setOnSwipeUp" { action<SwipeEvent>() }
        "setOnSwipeDown" { action<SwipeEvent>() }
        "setOnSwipeLeft" { action<SwipeEvent>() }
        "setOnSwipeRight" { action<SwipeEvent>() }
        "setOnTouchPressed" { action<TouchEvent>() }
        "setOnTouchMoved" { action<TouchEvent>() }
        "setOnTouchReleased" { action<TouchEvent>() }
        "setOnTouchStationary" { action<TouchEvent>() }
        "setOnKeyPressed" { action<KeyEvent>() }
        "setOnKeyReleased" { action<KeyEvent>() }
        "setOnKeyTyped" { action<KeyEvent>() }
        "setOnInputMethodTextChanged" { action<InputMethodEvent>() }
    }
    Scene::class {
        "setOnMouseClicked" { action<MouseEvent>() }
        "setOnMouseDragged" { action<MouseEvent>() }
        "setOnMouseEntered" { action<MouseEvent>() }
        "setOnMouseExited" { action<MouseEvent>() }
        "setOnMouseMoved" { action<MouseEvent>() }
        "setOnMousePressed" { action<MouseEvent>() }
        "setOnMouseReleased" { action<MouseEvent>() }
        "setOnDragDetected" { action<MouseEvent>() }
        "setOnMouseDragOver" { action<MouseDragEvent>() }
        "setOnMouseDragReleased" { action<MouseDragEvent>() }
        "setOnMouseDragEntered" { action<MouseDragEvent>() }
        "setOnMouseDragExited" { action<MouseDragEvent>() }
        "setOnScrollStarted" { action<ScrollEvent>() }
        "setOnScroll" { action<ScrollEvent>() }
        "setOnScrollFinished" { action<ScrollEvent>() }
        "setOnRotationStarted" { action<RotateEvent>() }
        "setOnRotate" { action<RotateEvent>() }
        "setOnRotationFinished" { action<RotateEvent>() }
        "setOnZoomStarted" { action<ZoomEvent>() }
        "setOnZoom" { action<ZoomEvent>() }
        "setOnZoomFinished" { action<ZoomEvent>() }
        "setOnSwipeUp" { action<SwipeEvent>() }
        "setOnSwipeDown" { action<SwipeEvent>() }
        "setOnSwipeLeft" { action<SwipeEvent>() }
        "setOnSwipeRight" { action<SwipeEvent>() }
        "setOnTouchPressed" { action<TouchEvent>() }
        "setOnTouchMoved" { action<TouchEvent>() }
        "setOnTouchReleased" { action<TouchEvent>() }
        "setOnTouchStationary" { action<TouchEvent>() }
        "setOnDragEntered" { action<DragEvent>() }
        "setOnDragExited" { action<DragEvent>() }
        "setOnDragOver" { action<DragEvent>() }
        "setOnDragDropped" { action<DragEvent>() }
        "setOnDragDone" { action<DragEvent>() }
        "setOnKeyPressed" { action<KeyEvent>() }
        "setOnKeyReleased" { action<KeyEvent>() }
        "setOnKeyTyped" { action<KeyEvent>() }
        "setOnInputMethodTextChanged" { action<InputMethodEvent>() }
        "setOnContextMenuRequested" { action<ContextMenuEvent>() }
    }
    // javafx.scene.control
    ButtonBase::class { "setOnAction" { action<ActionEvent>() } }
    (ChoiceBox::class.parameterizedBy(STAR)) {
        "setOnAction" { action<ActionEvent>() }
        "setOnShowing" { action<Event>() }
        "setOnShown" { action<Event>() }
        "setOnHiding" { action<Event>() }
        "setOnHidden" { action<Event>() }
    }
    (ComboBoxBase::class.parameterizedBy(STAR)) {
        "setOnAction" { action<ActionEvent>() }
        "setOnShowing" { action<Event>() }
        "setOnShown" { action<Event>() }
        "setOnHiding" { action<Event>() }
        "setOnHidden" { action<Event>() }
    }
    ContextMenu::class { "setOnAction" { action<ActionEvent>() } }
    (Dialog::class.parameterizedBy(STAR)) {
        "setOnShowing" { action<DialogEvent>() }
        "setOnShown" { action<DialogEvent>() }
        "setOnHiding" { action<DialogEvent>() }
        "setOnHidden" { action<DialogEvent>() }
        "setOnCloseRequest" { action<DialogEvent>() }
    }
    (ListView::class.parameterizedBy(T)) {
        val event = ListView.EditEvent::class.parameterizedBy(T)
        "setOnEditStart" { action(event) }
        "setOnEditCommit" { action(event) }
        "setOnEditCancel" { action(event) }
        "setOnScrollTo" { action(ScrollToEvent::class.parameterizedBy(Int::class)) }
    }
    Menu::class {
        "setOnShowing" { action<Event>() }
        "setOnShown" { action<Event>() }
        "setOnHiding" { action<Event>() }
        "setOnHidden" { action<Event>() }
    }
    MenuItem::class {
        "setOnAction" { action<ActionEvent>() }
        "setOnMenuValidation" { action<Event>() }
    }
    Tab::class {
        "setOnSelectionChanged" { action<Event>() }
        "setOnClosed" { action<Event>() }
        "setOnCloseRequest" { action<Event>() }
    }
    (TableColumn::class.parameterizedBy(S, T)) {
        val event = TableColumn.CellEditEvent::class.parameterizedBy(S, T)
        "setOnEditStart" { action(event) }
        "setOnEditCommit" { action(event) }
        "setOnEditCancel" { action(event) }
    }
    (TableView::class.parameterizedBy(S)) {
        "setOnSort" { action(SortEvent::class.parameterizedBy(TableView::class.parameterizedBy(S))) }
        "setOnScrollTo" { action(ScrollToEvent::class.parameterizedBy(Int::class)) }
        "setOnScrollToColumn" {
            action(ScrollToEvent::class.parameterizedBy(TableColumn::class.parameterizedBy(S, STAR)))
        }
    }
    TextField::class { "setOnAction" { action<ActionEvent>() } }
    (TreeTableColumn::class.parameterizedBy(S, T)) {
        val event = TreeTableColumn.CellEditEvent::class.parameterizedBy(S, T)
        "setOnEditStart" { action(event) }
        "setOnEditCommit" { action(event) }
        "setOnEditCancel" { action(event) }
    }
    (TreeTableView::class.parameterizedBy(T)) {
        "setOnSort" { action(SortEvent::class.parameterizedBy(TreeTableView::class.parameterizedBy(T))) }
        "setOnScrollTo" { action(ScrollToEvent::class.parameterizedBy(Int::class)) }
        "setOnScrollToColumn" {
            action(ScrollToEvent::class.parameterizedBy(TreeTableColumn::class.parameterizedBy(T, STAR)))
        }
    }
    (TreeView::class.parameterizedBy(T)) {
        val event = TreeView.EditEvent::class.parameterizedBy(T)
        "setOnEditStart" { action(event) }
        "setOnEditCommit" { action(event) }
        "setOnEditCancel" { action(event) }
        "setOnScrollTo" { action(ScrollToEvent::class.parameterizedBy(Int::class)) }
    }
    // javafx.scene.media
    Media::class { "setOnError" { action(*emptyArray()) } }
    MediaPlayer::class {
        "setOnError" { action(*emptyArray()) }
        "setOnMarker" { action<MediaMarkerEvent>() }
        "setOnEndOfMedia" { action(*emptyArray()) }
        "setOnReady" { action(*emptyArray()) }
        "setOnPlaying" { action(*emptyArray()) }
        "setOnPaused" { action(*emptyArray()) }
        "setOnStopped" { action(*emptyArray()) }
        "setOnHalted" { action(*emptyArray()) }
        "setOnRepeat" { action(*emptyArray()) }
        "setOnStalled" { action(*emptyArray()) }
    }
    MediaView::class { "setOnError" { action<MediaErrorEvent>() } }
    // javafx.scene.web
    WebEngine::class {
        "setOnAlert" { action(WebEvent::class.parameterizedBy(String::class)) }
        "setOnStatusChanged" { action(WebEvent::class.parameterizedBy(String::class)) }
        "setOnResized" { action(WebEvent::class.parameterizedBy(Rectangle2D::class)) }
        "setOnVisibilityChanged" { action(WebEvent::class.parameterizedBy(Boolean::class)) }
        "setOnError" { action<WebErrorEvent>() }
    }
    // javafx.scene.transform
    Transform::class { "setOnTransformChanged" { action<TransformChangedEvent>() } }
    // javafx.stage
    PopupWindow::class { "setOnAutoHide" { action<Event>() } }
    Window::class {
        "setOnCloseRequest" { action<WindowEvent>() }
        "setOnShowing" { action<WindowEvent>() }
        "setOnShown" { action<WindowEvent>() }
        "setOnHiding" { action<WindowEvent>() }
        "setOnHidden" { action<WindowEvent>() }
    }
}

<|start_filename|>ktfx-coroutines/src/ktfx/coroutines/_Media.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxCoroutinesKt")

package ktfx.coroutines

import javafx.scene.media.Media
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.launch
import kotlin.Unit
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName

/**
 * @see Media.setOnError
 */
public fun Media.onError(
    context: CoroutineContext = Dispatchers.JavaFx,
    action: suspend    
    CoroutineScope.() -> Unit
) {
    return setOnError { GlobalScope.launch(context) { action() } }
}


<|start_filename|>ktfx-commons/src/ktfx/internal/KtfxInternals.kt<|end_filename|>
package ktfx.internal

/** Ktfx internal class, ignore it. */
object KtfxInternals {

    /** No getter error message. */
    const val NO_GETTER: String = "Property does not have a getter."

    /** Some mutable backing fields are only used to set value. */
    fun noGetter(): Nothing = throw UnsupportedOperationException(NO_GETTER)
}


<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/TreeTableViewTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.control.ScrollToEvent
import javafx.scene.control.SortEvent
import javafx.scene.control.TreeTableColumn
import javafx.scene.control.TreeTableView
import com.hendraanggrian.ktfx.test.BaseTreeTableViewTest

class TreeTableViewTest : BaseTreeTableViewTest() {

    override fun <S> TreeTableView<S>.callOnSort(action: (SortEvent<TreeTableView<S>>) -> Unit) = onSort(action)
    override fun <S> TreeTableView<S>.callOnScrollTo(action: (ScrollToEvent<Int>) -> Unit) = onScrollTo(action)
    override fun <S> TreeTableView<S>.callOnScrollToColumn(action: (ScrollToEvent<TreeTableColumn<S, *>>) -> Unit) =
        onScrollToColumn(action)
}

<|start_filename|>ktfx-layouts/src/javafx/scene/control/ContextMenu.kt<|end_filename|>
@file:JvmMultifileClass
@file:JvmName("KtfxLayoutsKt")
@file:OptIn(ExperimentalContracts::class)

package ktfx.layouts

import javafx.scene.control.ContextMenu
import javafx.scene.control.Control
import javafx.scene.control.Tab
import javafx.scene.control.TableColumnBase
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

/** Create a [ContextMenu] with configuration block. */
inline fun contextMenu(
    configuration: (@KtfxLayoutDslMarker KtfxContextMenu).() -> Unit
): ContextMenu {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return KtfxContextMenu().apply(configuration)
}

/** Set a [ContextMenu] to this [Control]. */
fun Control.contextMenu(): ContextMenu =
    KtfxContextMenu().also { contextMenu = it }

/** Set a [ContextMenu] with configuration block to this [Control]. */
inline fun Control.contextMenu(
    configuration: (@KtfxLayoutDslMarker KtfxContextMenu).() -> Unit
): ContextMenu {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return ktfx.layouts.contextMenu(configuration).also { contextMenu = it }
}

/** Set a [ContextMenu] to this [Tab]. */
fun Tab.contextMenu(): ContextMenu =
    KtfxContextMenu().also { contextMenu = it }

/** Set a [ContextMenu] with configuration block to this [Tab]. */
inline fun Tab.contextMenu(
    configuration: (@KtfxLayoutDslMarker KtfxContextMenu).() -> Unit
): ContextMenu {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return ktfx.layouts.contextMenu(configuration).also { contextMenu = it }
}

/** Set a [ContextMenu] to this [TableColumnBase]. */
fun <S, T> TableColumnBase<S, T>.contextMenu(): ContextMenu =
    ktfx.layouts.contextMenu { }.also { contextMenu = it }

/** Set a [ContextMenu] with configuration block to this [TableColumnBase]. */
inline fun <S, T> TableColumnBase<S, T>.contextMenu(
    configuration: (@KtfxLayoutDslMarker KtfxContextMenu).() -> Unit
): ContextMenu {
    contract { callsInPlace(configuration, InvocationKind.EXACTLY_ONCE) }
    return ktfx.layouts.contextMenu(configuration).also { contextMenu = it }
}


<|start_filename|>ktfx-commons/tests/src/ktfx/PlatformTest.kt<|end_filename|>
package ktfx

import com.google.common.truth.Truth.assertThat
import com.hendraanggrian.ktfx.test.initToolkit
import javafx.application.ConditionalFeature
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.javafx.JavaFx
import kotlinx.coroutines.runBlocking
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class PlatformTest {

    @BeforeTest
    fun start() = initToolkit()

    @Test
    fun isFxThread2() {
        assertFalse(isFxThread())
        ktfx.runLater { assertTrue(isFxThread()) }
        runBlocking(Dispatchers.JavaFx) { assertTrue(isFxThread()) }
        runBlocking(Dispatchers.IO) { assertFalse(isFxThread()) }
    }

    @Test
    fun runLater() {
        // without receiver
        val list = mutableListOf<Int>()
        ktfx.runLater {
            assertTrue(isFxThread())
            list += 1
            assertThat(list).containsExactly(2, 1).inOrder()
        }
        list += 2

        // with receiver
        val list2 = mutableListOf<Int>()
        list2.runLater {
            assertTrue(isFxThread())
            list += 1
            assertThat(list2).containsExactly(2, 1).inOrder()
        }
        list2 += 2
    }

    @Test
    fun withLater() {
        val list = mutableListOf<Int>()
        withLater(list) {
            assertTrue(isFxThread())
            this += 1
            assertThat(list).containsExactly(2, 1).inOrder()
        }
        list += 2
    }

    @Test
    fun applyLater() {
        val list = mutableListOf<Int>()
        list.applyLater {
            assertTrue(isFxThread())
            this += 1
            assertThat(list).containsExactly(2, 1).inOrder()
        }
        list += 2
    }

    @Test
    fun alsoLater() {
        val list = mutableListOf<Int>()
        list.alsoLater {
            assertTrue(isFxThread())
            it += 1
            assertThat(list).containsExactly(2, 1).inOrder()
        }
        list += 2
    }

    @Test
    fun letLater() {
        val list = mutableListOf<Int>()
        list.letLater {
            assertTrue(isFxThread())
            it += 1
            assertThat(list).containsExactly(2, 1).inOrder()
        }
        list += 2
    }

    @Test
    fun repeatLater() {
        var i = 0
        repeatLater(10) {
            assertTrue(isFxThread())
            assertEquals(++i, it)
        }
    }

    @Test
    fun isSupported() = assertTrue(ConditionalFeature.CONTROLS.isSupported())
}


<|start_filename|>ktfx-commons/tests/src/ktfx/print/PageRangeTest.kt<|end_filename|>
package ktfx.print

import kotlin.test.Test
import kotlin.test.assertEquals

class PageRangeTest {

    @Test
    fun untilPage() {
        val range = 1 untilPage 3
        assertEquals(1, range.startPage)
        assertEquals(3, range.endPage)
    }
}


<|start_filename|>ktfx-listeners/tests/src/javafx/scene/control/TableColumnTest.kt<|end_filename|>
package ktfx.listeners

import javafx.scene.control.TableColumn
import com.hendraanggrian.ktfx.test.BaseTableColumnTest

class TableColumnTest : BaseTableColumnTest() {

    override fun <S, T> TableColumn<S, T>.callOnEditStart(action: (TableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditStart(action)

    override fun <S, T> TableColumn<S, T>.callOnEditCommit(action: (TableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditCommit(action)

    override fun <S, T> TableColumn<S, T>.callOnEditCancel(action: (TableColumn.CellEditEvent<S, T>) -> Unit) =
        onEditCancel(action)
}

<|start_filename|>ktfx-commons/tests/src/ktfx/CallbackTest.kt<|end_filename|>
package ktfx

import javafx.util.Duration
import ktfx.time.minutes
import ktfx.time.seconds
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull

class CallbackTest {

    @Test
    fun callbackOf() {
        assertNull(callbackOf<Duration, Double> { null }.call(Duration.INDEFINITE))
        assertEquals(1000.0, callbackOf<Duration, Double> { it.toMillis() }.call(1.seconds))
    }

    @Test
    fun invoke() {
        val callback = callbackOf<Int, Duration> { it.minutes }
        assertEquals(callback.call(1), callback(1))
    }
}
