aayush
08/24/2017, 12:33 PMclass MainView : View() {
override val root = gridpane()
val tv: TabbedView by di("tabView")
val sv: ShortcutView by di("shortcutView")
init {
with(root) {
add(tv.root, 0, 0)
add(sv.root, 1, 0)
isGridLinesVisible=true
columnConstraints.addAll(
newColConstraints(05.0), newColConstraints(15.0), newColConstraints(70.0))
rowConstraints.addAll(newRowConstraints(100.0))
}
}
}
class ShortcutView : View() {
override val root = hbox()
init {
with(root) {
listmenu(theme = "black") {
item(text = "Add Tab"){
onDoubleClick {
fire(AddTab(SampleTabView1::class))
}
}
}
}
}
}
class AddTab<T : UIComponent>(val type: KClass<T>) : FXEvent()
class TabbedView : View() {
override val root = hbox {
tabpane {
subscribe<AddTab<*>> {
val uicmp = find(it.type)
if (tabs.map { it.content }.none { it == uicmp.root })
add(uicmp)
}
}
}
}
class SampleTabView1 : Fragment("Sample Tab 1") {
override val root = vbox {
label("Content in Sample Tab 1")
}
}
fun newColConstraints(percentage: Double): ColumnConstraints {
val colCons = ColumnConstraints()
colCons.percentWidth = percentage
colCons.hgrow = Priority.ALWAYS
return colCons
}
fun newRowConstraints(percentage: Double): RowConstraints {
val rowCons = RowConstraints()
rowCons.percentHeight = percentage
rowCons.vgrow = Priority.ALWAYS
return rowCons
}