<commit_before>package tornadofx

import javafx.event.EventTarget
import javafx.geometry.Orientation
import javafx.scene.Group
import javafx.scene.Node
import javafx.scene.control.*
import javafx.scene.layout.*

fun GridPane.row(title: String? = null, op: (Pane.() -> Unit)? = null) {
    val GridPaneRowIdKey = "TornadoFX.GridPaneRowId";

    properties[GridPaneRowIdKey] = if (properties.containsKey(GridPaneRowIdKey)) properties[GridPaneRowIdKey] as Int + 1 else 1

    // Allow the caller to add children to a fake pane
    val fake = Pane()
    if (title != null)
        fake.children.add(Label(title))

    op?.invoke(fake)

    // Create a new row in the GridPane and add the children added to the fake pane
    addRow(properties[GridPaneRowIdKey] as Int, *fake.children.toTypedArray())
}

fun ToolBar.spacer(prio: Priority = Priority.ALWAYS, op: (Pane.() -> Unit)? = null): Pane {
    val pane = Pane().apply { HBox.setHgrow(this, prio) }
    op?.invoke(pane)
    add(pane)
    return pane
}

fun HBox.spacer(prio: Priority = Priority.ALWAYS, op: (Pane.() -> Unit)? = null) = opcr(this, Pane().apply { HBox.setHgrow(this, prio) }, op)
fun VBox.spacer(prio: Priority = Priority.ALWAYS, op: (Pane.() -> Unit)? = null) = opcr(this, Pane().apply { VBox.setVgrow(this, prio) }, op)

fun EventTarget.toolbar(vararg nodes: Node, op: (ToolBar.() -> Unit)? = null): ToolBar {
    val toolbar = ToolBar()
    if (nodes.isNotEmpty())
        toolbar.items.addAll(nodes)
    opcr(this, toolbar, op)
    return toolbar
}


@Deprecated("No need to wrap ToolBar children in children{} anymore. Remove the wrapper and all builder items will still be added as before.", ReplaceWith("no children{} wrapper"), DeprecationLevel.WARNING)
fun ToolBar.children(op: ToolBar.() -> Unit): ToolBar {
    op(this)
    return this
}

fun EventTarget.hbox(spacing: Double? = null, children: Iterable<Node>? = null, op: (HBox.() -> Unit)? = null): HBox {
    val hbox = HBox()
    if (children != null)
        hbox.children.addAll(children)
    if (spacing != null) hbox.spacing = spacing
    return opcr(this, hbox, op)
}

fun EventTarget.vbox(spacing: Double? = null, children: Iterable<Node>? = null, op: (VBox.() -> Unit)? = null): VBox {
    val vbox = VBox()
    if (children != null)
        vbox.children.addAll(children)
    if (spacing != null) vbox.spacing = spacing
    return opcr(this, vbox, op)
}

fun ToolBar.separator(orientation: Orientation = Orientation.HORIZONTAL, op: (Separator.() -> Unit)? = null): Separator {
    val separator = Separator(orientation)
    op?.invoke(separator)
    add(separator)
    return separator
}

fun EventTarget.separator(orientation: Orientation = Orientation.HORIZONTAL, op: (Separator.() -> Unit)? = null) = opcr(this, Separator(orientation), op)

fun EventTarget.group(initialChildren: Iterable<Node>? = null, op: (Group.() -> Unit)? = null) = opcr(this, Group().apply { if (initialChildren != null) children.addAll(initialChildren) }, op)
fun EventTarget.stackpane(initialChildren: Iterable<Node>? = null, op: (StackPane.() -> Unit)? = null) = opcr(this, StackPane().apply { if (initialChildren != null) children.addAll(initialChildren) }, op)
fun EventTarget.gridpane(op: (GridPane.() -> Unit)? = null) = opcr(this, GridPane(), op)
fun EventTarget.flowpane(op: (FlowPane.() -> Unit)? = null) = opcr(this, FlowPane(), op)
fun EventTarget.tilepane(op: (TilePane.() -> Unit)? = null) = opcr(this, TilePane(), op)
fun EventTarget.borderpane(op: (BorderPane.() -> Unit)? = null) = opcr(this, BorderPane(), op)

@Deprecated("Properties set on the container will be lost if you add only a single child Node", ReplaceWith("BorderPane.top = yourNode { }"), DeprecationLevel.WARNING)
fun BorderPane.top(op: (Pane.() -> Unit)? = null) {
    val vbox = VBox()
    op?.invoke(vbox)
    top = if (vbox.children.size == 1) vbox.children[0] else vbox
}

@Deprecated("Use BorderPane.top = yourNode {} instead", ReplaceWith("BorderPane.top = yourNode { }"), DeprecationLevel.WARNING)
fun <T : Node> BorderPane.top(topNode: T, op: (T.() -> Unit)? = null): T {
    top = topNode
    return opcr(this, topNode, op)
}

@Deprecated("Use BorderPane.bottom = yourNode {} instead", ReplaceWith("BorderPane.bottom = yourNode { }"), DeprecationLevel.WARNING)
fun <T : Node> BorderPane.bottom(bottomNode: T, op: (T.() -> Unit)? = null): T {
    bottom = bottomNode
    return opcr(this, bottomNode, op)
}

@Deprecated("Use BorderPane.left = yourNode {} instead", ReplaceWith("BorderPane.left = yourNode { }"), DeprecationLevel.WARNING)
fun <T : Node> BorderPane.left(leftNode: T, op: (T.() -> Unit)? = null): T {
    left = leftNode
    return opcr(this, leftNode, op)
}

@Deprecated("Use BorderPane.right = yourNode {} instead", ReplaceWith("BorderPane.right = yourNode { }"), DeprecationLevel.WARNING)
fun <T : Node> BorderPane.right(rightNode: T, op: (T.() -> Unit)? = null): T {
    right = rightNode
    return opcr(this, rightNode, op)
}

@Deprecated("Use BorderPane.center = yourNode {} instead", ReplaceWith("BorderPane.center = yourNode { }"), DeprecationLevel.WARNING)
fun <T : Node> BorderPane.center(centerNode: T, op: (T.() -> Unit)? = null): T {
    center = centerNode
    return opcr(this, centerNode, op)
}

@Deprecated("Properties set on the container will be lost if you add only a single child Node", ReplaceWith("BorderPane.bottom = yourNode { }"), DeprecationLevel.WARNING)
fun BorderPane.bottom(op: (Pane.() -> Unit)? = null) {
    val vbox = VBox()
    op?.invoke(vbox)
    bottom = if (vbox.children.size == 1) vbox.children[0] else vbox
}

@Deprecated("Properties set on the container will be lost if you add only a single child Node", ReplaceWith("BorderPane.left = yourNode { }"), DeprecationLevel.WARNING)
fun BorderPane.left(op: (Pane.() -> Unit)? = null) {
    val vbox = VBox()
    op?.invoke(vbox)
    left = if (vbox.children.size == 1) vbox.children[0] else vbox
}

@Deprecated("Properties set on the container will be lost if you add only a single child Node", ReplaceWith("BorderPane.right = yourNode { }"), DeprecationLevel.WARNING)
fun BorderPane.right(op: (Pane.() -> Unit)? = null) {
    val vbox = VBox()
    op?.invoke(vbox)
    right = if (vbox.children.size == 1) vbox.children[0] else vbox
}

@Deprecated("Properties set on the container will be lost if you add only a single child Node", ReplaceWith("BorderPane.center = yourNode { }"), DeprecationLevel.WARNING)<commit_msg>Removed deprecation on alternative borderpane builders<commit_after>package tornadofx

import javafx.event.EventTarget
import javafx.geometry.Orientation
import javafx.scene.Group
import javafx.scene.Node
import javafx.scene.control.*
import javafx.scene.layout.*

fun GridPane.row(title: String? = null, op: (Pane.() -> Unit)? = null) {
    val GridPaneRowIdKey = "TornadoFX.GridPaneRowId";

    properties[GridPaneRowIdKey] = if (properties.containsKey(GridPaneRowIdKey)) properties[GridPaneRowIdKey] as Int + 1 else 1

    // Allow the caller to add children to a fake pane
    val fake = Pane()
    if (title != null)
        fake.children.add(Label(title))

    op?.invoke(fake)

    // Create a new row in the GridPane and add the children added to the fake pane
    addRow(properties[GridPaneRowIdKey] as Int, *fake.children.toTypedArray())
}

fun ToolBar.spacer(prio: Priority = Priority.ALWAYS, op: (Pane.() -> Unit)? = null): Pane {
    val pane = Pane().apply { HBox.setHgrow(this, prio) }
    op?.invoke(pane)
    add(pane)
    return pane
}

fun HBox.spacer(prio: Priority = Priority.ALWAYS, op: (Pane.() -> Unit)? = null) = opcr(this, Pane().apply { HBox.setHgrow(this, prio) }, op)
fun VBox.spacer(prio: Priority = Priority.ALWAYS, op: (Pane.() -> Unit)? = null) = opcr(this, Pane().apply { VBox.setVgrow(this, prio) }, op)

fun EventTarget.toolbar(vararg nodes: Node, op: (ToolBar.() -> Unit)? = null): ToolBar {
    val toolbar = ToolBar()
    if (nodes.isNotEmpty())
        toolbar.items.addAll(nodes)
    opcr(this, toolbar, op)
    return toolbar
}


@Deprecated("No need to wrap ToolBar children in children{} anymore. Remove the wrapper and all builder items will still be added as before.", ReplaceWith("no children{} wrapper"), DeprecationLevel.WARNING)
fun ToolBar.children(op: ToolBar.() -> Unit): ToolBar {
    op(this)
    return this
}

fun EventTarget.hbox(spacing: Double? = null, children: Iterable<Node>? = null, op: (HBox.() -> Unit)? = null): HBox {
    val hbox = HBox()
    if (children != null)
        hbox.children.addAll(children)
    if (spacing != null) hbox.spacing = spacing
    return opcr(this, hbox, op)
}

fun EventTarget.vbox(spacing: Double? = null, children: Iterable<Node>? = null, op: (VBox.() -> Unit)? = null): VBox {
    val vbox = VBox()
    if (children != null)
        vbox.children.addAll(children)
    if (spacing != null) vbox.spacing = spacing
    return opcr(this, vbox, op)
}

fun ToolBar.separator(orientation: Orientation = Orientation.HORIZONTAL, op: (Separator.() -> Unit)? = null): Separator {
    val separator = Separator(orientation)
    op?.invoke(separator)
    add(separator)
    return separator
}

fun EventTarget.separator(orientation: Orientation = Orientation.HORIZONTAL, op: (Separator.() -> Unit)? = null) = opcr(this, Separator(orientation), op)

fun EventTarget.group(initialChildren: Iterable<Node>? = null, op: (Group.() -> Unit)? = null) = opcr(this, Group().apply { if (initialChildren != null) children.addAll(initialChildren) }, op)
fun EventTarget.stackpane(initialChildren: Iterable<Node>? = null, op: (StackPane.() -> Unit)? = null) = opcr(this, StackPane().apply { if (initialChildren != null) children.addAll(initialChildren) }, op)
fun EventTarget.gridpane(op: (GridPane.() -> Unit)? = null) = opcr(this, GridPane(), op)
fun EventTarget.flowpane(op: (FlowPane.() -> Unit)? = null) = opcr(this, FlowPane(), op)
fun EventTarget.tilepane(op: (TilePane.() -> Unit)? = null) = opcr(this, TilePane(), op)
fun EventTarget.borderpane(op: (BorderPane.() -> Unit)? = null) = opcr(this, BorderPane(), op)

@Deprecated("Properties set on the container will be lost if you add only a single child Node", ReplaceWith("BorderPane.top = yourNode { }"), DeprecationLevel.WARNING)
fun BorderPane.top(op: (Pane.() -> Unit)? = null) {
    val vbox = VBox()
    op?.invoke(vbox)
    top = if (vbox.children.size == 1) vbox.children[0] else vbox
}

fun <T : Node> BorderPane.top(topNode: T, op: (T.() -> Unit)? = null): T {
    top = topNode
    return opcr(this, topNode, op)
}

fun <T : Node> BorderPane.bottom(bottomNode: T, op: (T.() -> Unit)? = null): T {
    bottom = bottomNode
    return opcr(this, bottomNode, op)
}

fun <T : Node> BorderPane.left(leftNode: T, op: (T.() -> Unit)? = null): T {
    left = leftNode
    return opcr(this, leftNode, op)
}

fun <T : Node> BorderPane.right(rightNode: T, op: (T.() -> Unit)? = null): T {
    right = rightNode
    return opcr(this, rightNode, op)
}

fun <T : Node> BorderPane.center(centerNode: T, op: (T.() -> Unit)? = null): T {
    center = centerNode
    return opcr(this, centerNode, op)
}

@Deprecated("Properties set on the container will be lost if you add only a single child Node", ReplaceWith("BorderPane.bottom = yourNode { }"), DeprecationLevel.WARNING)
fun BorderPane.bottom(op: (Pane.() -> Unit)? = null) {
    val vbox = VBox()
    op?.invoke(vbox)
    bottom = if (vbox.children.size == 1) vbox.children[0] else vbox
}

@Deprecated("Properties set on the container will be lost if you add only a single child Node", ReplaceWith("BorderPane.left = yourNode { }"), DeprecationLevel.WARNING)
fun BorderPane.left(op: (Pane.() -> Unit)? = null) {
    val vbox = VBox()
    op?.invoke(vbox)
    left = if (vbox.children.size == 1) vbox.children[0] else vbox
}

@Deprecated("Properties set on the container will be lost if you add only a single child Node", ReplaceWith("BorderPane.right = yourNode { }"), DeprecationLevel.WARNING)
fun BorderPane.right(op: (Pane.() -> Unit)? = null) {
    val vbox = VBox()
    op?.invoke(vbox)
    right = if (vbox.children.size == 1) vbox.children[0] else vbox
}

@Deprecated("Properties set on the container will be lost if you add only a single child Node", ReplaceWith("BorderPane.center = yourNode { }"), DeprecationLevel.WARNING)
{'fraction_non_alphanumeric': 0.15295367268567694, 'fraction_numerical': 0.0016341204346760356, 'mean_word_length': 4.171102661596958, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6940910', 'n_tokens_mistral': 4136, 'n_tokens_neox': 3989, 'n_words': 1147}