bkenn
05/31/2018, 2:01 AMclass MainView : View("Hello TornadoFX") {
val catModel = CatModel()
val cats = mutableListOf<Cat>().observable()
init {
cats.add(Cat("<https://cdn.pixabay.com/photo/2018/05/04/16/50/cat-3374422_960_720.jpg>"))
cats.add(Cat("<https://cdn.pixabay.com/photo/2018/03/26/20/49/tiger-3264048_960_720.jpg>"))
cats.add(Cat("<https://cdn.pixabay.com/photo/2017/12/26/16/09/lion-3040797_960_720.jpg>"))
cats.add(Cat("<https://cdn.pixabay.com/photo/2017/11/14/13/06/kitty-2948404_960_720.jpg>"))
cats.add(Cat("<https://cdn.pixabay.com/photo/2014/04/13/20/49/cat-323262_960_720.jpg>"))
}
override val root = splitpane {
setPrefSize(1000.0, 600.0)
tableview(cats) {
column("URL", Cat::catImageProperty)
bindSelected(catModel)
}
vbox {
alignment = Pos.TOP_CENTER
label(catModel.catImage) {
style {
fontWeight = FontWeight.BOLD
font = Font.font("Arial Bold")
}
}
imageview(catModel.catImage) {
fitWidth = 500.0
fitHeight = 400.0
isPreserveRatio = true
isCache = true
}
}
}
}
class Cat(cateImage: String) {
val catImageProperty = SimpleStringProperty(cateImage)
var catImage by catImageProperty
override fun toString(): String {
return "Cat (catImage=$catImage)"
}
}
class CatModel : ItemViewModel<Cat>() {
val catImage = bind(Cat::catImageProperty)
}