<commit_before>package tornadofx.testapps

import javafx.geometry.Pos
import javafx.scene.paint.*
import javafx.scene.text.FontWeight
import tornadofx.*

class NewViewTransitionRoot : App(NewViewTransitionMain::class, NewViewTransitionStyles::class)

class NewViewTransitionVBox : App(VBoxRootView::class, NewViewTransitionStyles::class) {
    class VBoxRootView : View("Switching Sub Views In VBox") {
        override val root = vbox {
            label("Top").addClass(NewViewTransitionStyles.topLabel)
            this += NewViewTransitionMain::class
            label("Bottom").addClass(NewViewTransitionStyles.bottomLabel)
        }
    }
}

class NewViewTransitionBorderPane : App(BorderPaneRootView::class, NewViewTransitionStyles::class) {
    class BorderPaneRootView : View("Switching Sub Views In BorderPane") {
        override val root = borderpane {
            top = label("Top") { addClass(NewViewTransitionStyles.topLabel) }
            right = label("Right") { addClass(NewViewTransitionStyles.rightLabel) }
            bottom = label("Bottom") { addClass(NewViewTransitionStyles.bottomLabel) }
            left = label("Left") { addClass(NewViewTransitionStyles.leftLabel) }
            center(NewViewTransitionMain::class)
        }
    }
}

abstract class NewViewTransitionSwapView(name: String, cssClass: CssRule) : View("Switching Views On Scene Root") {
    val controller: NewViewTransitionController by inject()
    val button = button(controller.firstTransition) { setOnAction { swap() } }
    override val root = stackpane {
        vbox {
            addClass(NewViewTransitionStyles.box, cssClass)
            label(name)
            this += button
        }
    }

    abstract fun swap()
}

class NewViewTransitionMain : NewViewTransitionSwapView("Main", NewViewTransitionStyles.red) {
    val alt: NewViewTransitionAlternate by inject()
    override fun swap() {
        controller.swap(this, alt)
    }
}

class NewViewTransitionAlternate : NewViewTransitionSwapView("Alternate", NewViewTransitionStyles.blue) {
    val main: NewViewTransitionMain by inject()
    override fun swap() {
        controller.swap(this, main)
    }
}

class NewViewTransitionController : Controller() {
    private val time = .25.seconds
    private val doubleTime = time.multiply(2.0)
    private val fades = listOf(
            "Black" to Color.BLACK,
            "White" to Color.WHITE,
            "Red" to Color.RED,
            "Fade" to LinearGradient(0.0, 1.0, 1.0, 0.0, true, CycleMethod.NO_CYCLE, Stop(0.0, Color.BLACK), Stop(1.0, Color.WHITE)),
            "Crazy" to RadialGradient(0.0, 0.0, 150.0, 100.0, 75.0, false, CycleMethod.REPEAT,
                    Stop(0.0, Color.RED), Stop(0.33, Color.RED),
                    Stop(0.33, Color.GREEN), Stop(0.66, Color.GREEN),
                    Stop(0.66, Color.BLUE), Stop(1.0, Color.BLUE)
            )
    )

    private val transitions = listOf(
            "None" to null,
            "Fade" to ViewTransition.Fade(time),
            *fades.map { "Fade Through ${it.first}" to ViewTransition.FadeThrough(doubleTime, it.second) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Slide $it" to ViewTransition.Slide(time, it) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Cover $it" to ViewTransition.Cover(time, it) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Reveal $it" to ViewTransition.Reveal(time, it) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Metro $it" to ViewTransition.Metro(time, it) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Swap $it" to ViewTransition.Swap(doubleTime, it) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Flip $it" to ViewTransition.Flip(time, it) }.toTypedArray(),
            "NewsFlash" to ViewTransition.NewsFlash(doubleTime, 2.0)
    )
    val firstTransition = transitions[0].first
    private var currentTransition = 0
    fun swap(current: NewViewTransitionSwapView, replacement: NewViewTransitionSwapView) {
        val t = transitions[currentTransition].second
        currentTransition = (currentTransition + 1) % transitions.size
        replacement.button.text = transitions[currentTransition].first
        current.replaceWith(replacement, t)
    }
}

class NewViewTransitionStyles : Stylesheet() {
    companion object {
        val box by cssclass()
        val red by cssclass()
        val blue by cssclass()
        val bg by cssproperty<Paint>("-fx-background-color")
        val nuke by cssproperty<Paint>()
        val topLabel by cssclass()
        val rightLabel by cssclass()
        val bottomLabel by cssclass()
        val leftLabel by cssclass()

        fun labelMix(gray: Double) = mixin {
            maxWidth = infinity
            maxHeight = infinity
            alignment = Pos.BASELINE_CENTER
            padding = box(12.px)
            fontSize = 24.px
            backgroundColor += Color.gray(gray)
            textFill = Color.gray(1 - gray)
        }
    }

    init {
        box {
            prefWidth = 400.px
            prefHeight = 300.px
            spacing = 12.px
            alignment = Pos.CENTER
            s(label, button) {
                textFill = Color.WHITE
                fontSize = 36.px
                fontWeight = FontWeight.BOLD
                alignment = Pos.BASELINE_CENTER
            }
            val boxMix = mixin {
                bg force nuke
                button {
                    bg force raw("derive(${nuke.name}, -10%)")
                    and(hover) {
                        bg force raw("derive(${nuke.name}, -15%)")
                    }
                }
            }
            and(red) {
                nuke.value = Color(.75, .5, .5, 1.0)
                +boxMix
            }
            and(blue) {
                nuke.value = Color(.5, .5, .75, 1.0)
                +boxMix
            }
        }
        topLabel {
            +labelMix(0.0)
        }
        rightLabel {
            +labelMix(0.25)
        }
        bottomLabel {
            +labelMix(1.0)
        }
        leftLabel {
            +labelMix(0.75)
        }
    }
}
<commit_msg>Made button assignment cleaner<commit_after>package tornadofx.testapps

import javafx.geometry.Pos
import javafx.scene.control.Button
import javafx.scene.paint.*
import javafx.scene.text.FontWeight
import tornadofx.*

class NewViewTransitionRoot : App(NewViewTransitionMain::class, NewViewTransitionStyles::class)

class NewViewTransitionVBox : App(VBoxRootView::class, NewViewTransitionStyles::class) {
    class VBoxRootView : View("Switching Sub Views In VBox") {
        override val root = vbox {
            label("Top").addClass(NewViewTransitionStyles.topLabel)
            this += NewViewTransitionMain::class
            label("Bottom").addClass(NewViewTransitionStyles.bottomLabel)
        }
    }
}

class NewViewTransitionBorderPane : App(BorderPaneRootView::class, NewViewTransitionStyles::class) {
    class BorderPaneRootView : View("Switching Sub Views In BorderPane") {
        override val root = borderpane {
            top = label("Top") { addClass(NewViewTransitionStyles.topLabel) }
            right = label("Right") { addClass(NewViewTransitionStyles.rightLabel) }
            bottom = label("Bottom") { addClass(NewViewTransitionStyles.bottomLabel) }
            left = label("Left") { addClass(NewViewTransitionStyles.leftLabel) }
            center(NewViewTransitionMain::class)
        }
    }
}

abstract class NewViewTransitionSwapView(name: String, cssClass: CssRule) : View("Switching Views On Scene Root") {
    val controller: NewViewTransitionController by inject()
    lateinit var button: Button
    override val root = stackpane {
        vbox {
            addClass(NewViewTransitionStyles.box, cssClass)
            label(name)
            button = button(controller.firstTransition) { setOnAction { swap() } }
        }
    }

    abstract fun swap()
}

class NewViewTransitionMain : NewViewTransitionSwapView("Main", NewViewTransitionStyles.red) {
    val alt: NewViewTransitionAlternate by inject()
    override fun swap() {
        controller.swap(this, alt)
    }
}

class NewViewTransitionAlternate : NewViewTransitionSwapView("Alternate", NewViewTransitionStyles.blue) {
    val main: NewViewTransitionMain by inject()
    override fun swap() {
        controller.swap(this, main)
    }
}

class NewViewTransitionController : Controller() {
    private val time = .25.seconds
    private val doubleTime = time.multiply(2.0)
    private val fades = listOf(
            "Black" to Color.BLACK,
            "White" to Color.WHITE,
            "Red" to Color.RED,
            "Fade" to LinearGradient(0.0, 1.0, 1.0, 0.0, true, CycleMethod.NO_CYCLE, Stop(0.0, Color.BLACK), Stop(1.0, Color.WHITE)),
            "Crazy" to RadialGradient(0.0, 0.0, 150.0, 100.0, 75.0, false, CycleMethod.REPEAT,
                    Stop(0.0, Color.RED), Stop(0.33, Color.RED),
                    Stop(0.33, Color.GREEN), Stop(0.66, Color.GREEN),
                    Stop(0.66, Color.BLUE), Stop(1.0, Color.BLUE)
            )
    )

    private val transitions = listOf(
            "None" to null,
            "Fade" to ViewTransition.Fade(time),
            *fades.map { "Fade Through ${it.first}" to ViewTransition.FadeThrough(doubleTime, it.second) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Slide $it" to ViewTransition.Slide(time, it) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Cover $it" to ViewTransition.Cover(time, it) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Reveal $it" to ViewTransition.Reveal(time, it) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Metro $it" to ViewTransition.Metro(time, it) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Swap $it" to ViewTransition.Swap(doubleTime, it) }.toTypedArray(),
            *ViewTransition.Direction.values().map { "Flip $it" to ViewTransition.Flip(time, it) }.toTypedArray(),
            "NewsFlash" to ViewTransition.NewsFlash(doubleTime, 2.0)
    )
    val firstTransition = transitions[0].first
    private var currentTransition = 0
    fun swap(current: NewViewTransitionSwapView, replacement: NewViewTransitionSwapView) {
        val t = transitions[currentTransition].second
        currentTransition = (currentTransition + 1) % transitions.size
        replacement.button.text = transitions[currentTransition].first
        current.replaceWith(replacement, t)
    }
}

class NewViewTransitionStyles : Stylesheet() {
    companion object {
        val box by cssclass()
        val red by cssclass()
        val blue by cssclass()
        val bg by cssproperty<Paint>("-fx-background-color")
        val nuke by cssproperty<Paint>()
        val topLabel by cssclass()
        val rightLabel by cssclass()
        val bottomLabel by cssclass()
        val leftLabel by cssclass()

        fun labelMix(gray: Double) = mixin {
            maxWidth = infinity
            maxHeight = infinity
            alignment = Pos.BASELINE_CENTER
            padding = box(12.px)
            fontSize = 24.px
            backgroundColor += Color.gray(gray)
            textFill = Color.gray(1 - gray)
        }
    }

    init {
        box {
            prefWidth = 400.px
            prefHeight = 300.px
            spacing = 12.px
            alignment = Pos.CENTER
            s(label, button) {
                textFill = Color.WHITE
                fontSize = 36.px
                fontWeight = FontWeight.BOLD
                alignment = Pos.BASELINE_CENTER
            }
            val boxMix = mixin {
                bg force nuke
                button {
                    bg force raw("derive(${nuke.name}, -10%)")
                    and(hover) {
                        bg force raw("derive(${nuke.name}, -15%)")
                    }
                }
            }
            and(red) {
                nuke.value = Color(.75, .5, .5, 1.0)
                +boxMix
            }
            and(blue) {
                nuke.value = Color(.5, .5, .75, 1.0)
                +boxMix
            }
        }
        topLabel {
            +labelMix(0.0)
        }
        rightLabel {
            +labelMix(0.25)
        }
        bottomLabel {
            +labelMix(1.0)
        }
        leftLabel {
            +labelMix(0.75)
        }
    }
}

{'fraction_non_alphanumeric': 0.10793955384984409, 'fraction_numerical': 0.014871671863756297, 'mean_word_length': 2.1689891056498607, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2888125', 'n_tokens_mistral': 3676, 'n_tokens_neox': 3551, 'n_words': 776}