class TO_FirstModal : View("First Modal") { override val root = vbox { label("first modal") button("Next") { action { find().openModal() } } padding = Insets(100.0) } } class TO_SecondModal : View("Second Modal") { override val root = vbox { label("second modal") button("Next") { action { find().openModal() } } padding = Insets(100.0) } } class TO_ThirdModal : View("Second Modal") { override val root = vbox { label("third modal") button("Finish") { action { find().close() find().close() find().close() } } padding = Insets(100.0) } } const val TIMEOUT_CHECK_INTERVAL = 5L const val TIMEOUTVAL = 15L class TO_ClosingModalsMainView : View("Closing Modals") { val timeoutAccural = SimpleLongProperty() override val root = vbox { vbox { label("main view") button("Start") { action { find().openModal() } } spacing = 2.0 padding = Insets(10.0) vgrow = Priority.ALWAYS } separator() hbox { label("Timeout in:") label(SimpleLongProperty(TIMEOUTVAL).subtract(timeoutAccural).asString()) padding = Insets(10.0) spacing = 2.0 } spacing = 2.0 prefWidth = 667.0 prefHeight = 376.0 } fun startTimer() { val timeline = Timeline(KeyFrame(Duration.seconds(TIMEOUT_CHECK_INTERVAL.toDouble()), checkForTimeout)) timeline.setCycleCount(Animation.INDEFINITE) timeline.play() } val checkForTimeout = EventHandler { timeoutAccural.value += TIMEOUT_CHECK_INTERVAL if( timeoutAccural >= TIMEOUTVAL ) { val tm = find() if( tm.modalStage != null && tm.modalStage!!.isShowing) tm.close() val sm = find() if( sm.modalStage != null && sm.modalStage!!.isShowing) sm.close() val fm = find() if( fm.modalStage != null && fm.modalStage!!.isShowing) fm.close() } } override fun onDock() { startTimer() } } class TO_ClosingModals : App(TO_ClosingModalsMainView::class) fun main(args: Array) { launch(args) }