Skip to content

Instantly share code, notes, and snippets.

@thomasnield
Last active August 21, 2016 23:59
Show Gist options
  • Save thomasnield/c2636f55cce00ed4515bd204e875aa59 to your computer and use it in GitHub Desktop.
Save thomasnield/c2636f55cce00ed4515bd204e875aa59 to your computer and use it in GitHub Desktop.
/* Include these Gradle dependencies
compile 'no.tornado:tornadofx:1.5.4'
compile 'com.github.thomasnield:rxkotlinfx:0.1.4'
compile 'io.reactivex:rxkotlin:0.60.0'
*/
class MyView : View() {
val items = FXCollections.observableArrayList("Alpha","Beta","Gamma",
"Delta","Epsilon","Zeta","Eta")
override val root = vbox {
val listView = listview(items)
val typeLabel = label {
style {
fontSize = 20.px
textFill = Color.RED
}
}
val burstyMulticast = listView.events(KeyEvent.KEY_TYPED).publish().refCount().map { it.character }
burstyMulticast.throttleWithTimeout(500, TimeUnit.MILLISECONDS).startWith("")
.doOnNextFx { typeLabel.text = "" }
.switchMap {
burstyMulticast.scan { x,y -> x + y }
.doOnNextFx { typeLabel.text = it }
.switchMap { input ->
items.toObservable()
.filter { it.toUpperCase().startsWith(input.toUpperCase()) }
}
}.observeOnFx().subscribe { listView.selectionModel.select(it) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment