pike
08/17/2017, 8:33 AMaayush
08/17/2017, 11:48 AMclass MainView : View() {
val persons: ObservableList<Person> = FXCollections.observableArrayList<Person>()
override val root = vbox {
textfield {
action {
persons.add(Person(text, false))
clear()
}
}
listview(persons) {
cellFormat {
graphic = cache {
form {
fieldset {
hbox {
checkbox {
action {
persons.get(persons.indexOf(it)).selection = !it.selection
}
}
label(it.name) {
style {
fontSize = 12.px
}
toggleClass(Styles.strikethrough, it.selection)
}
}
}
}
}
}
}
}
}
class Person(val name: String, var selection: Boolean)
edvin
08/17/2017, 11:49 AMaayush
08/17/2017, 11:49 AMaayush
08/17/2017, 11:49 AMaayush
08/17/2017, 12:07 PMaayush
08/17/2017, 12:09 PMaayush
08/17/2017, 12:09 PMaayush
08/17/2017, 12:09 PMedvin
08/17/2017, 12:17 PMaayush
08/17/2017, 12:18 PMaayush
08/17/2017, 12:19 PMclass MainView : View() {
val persons: ObservableList<Person> = FXCollections.observableArrayList<Person>()
override val root = vbox {
textfield {
action {
persons.add(Person(text, false))
clear()
}
}
listview(persons) {
cellFormat {
graphic = cache {
form {
fieldset {
hbox {
checkbox {
if (it.selection) {
this.isSelected = true
}
action {
persons.get(persons.indexOf(it)).selection = !it.selection
}
}
label(it.name) {
style {
fontSize = 12.px
}
}
}
}
}
}
}
}
}
}
class Person(val name: String, var selection: Boolean)
edvin
08/17/2017, 12:28 PMedvin
08/17/2017, 12:30 PMaayush
08/17/2017, 12:31 PMedvin
08/17/2017, 12:38 PMedvin
08/17/2017, 12:38 PMnimakro
08/17/2017, 12:42 PMaayush
08/17/2017, 12:44 PMnimakro
08/17/2017, 12:46 PMedvin
08/17/2017, 1:09 PMJuan
08/17/2017, 1:40 PMhttp://i.imgur.com/dtluWUP.png▾
edvin
08/17/2017, 2:07 PMTodoList
?Juan
08/17/2017, 2:08 PMpackage todolist.app
import todolist.stylessheets.Styles
import todolist.views.TodoList
import tornadofx.*
class TodoList : App() {
override val primaryView = TodoList::class
init {
setStageIcon(resources.image("icon.png"))
importStylesheet(Styles::class)
}
}
edvin
08/17/2017, 2:09 PMedvin
08/17/2017, 2:09 PMedvin
08/17/2017, 2:09 PMJuan
08/17/2017, 2:10 PMJuan
08/17/2017, 2:10 PMpackage todolist.views
import javafx.animation.Interpolator
import javafx.geometry.Pos
import javafx.scene.Node
import javafx.scene.control.Button
import javafx.scene.control.TextField
import javafx.scene.layout.VBox
import todolist.stylessheets.Styles
import tornadofx.*
class TodoList : View() {
override val root = vbox()
companion object {
var taskInput: TextField by singleAssign()
var addTaskButton: Button by singleAssign()
var tasksList: VBox by singleAssign()
}
init {
with(root) {
title = "To-do List App"
vbox {
vbox {
addClass(Styles.header)
text("To-do List Manager") {
alignment = Pos.CENTER
addClass(Styles.h1)
vboxConstraints {
marginBottom = 20.0
}
}
taskInput = textfield()
taskInput.addClass(Styles.taskInput)
taskInput.apply {
tooltip("Type the task you're yet to do")
}
addTaskButton = button("Add Task") {
alignment = Pos.CENTER
addClass(Styles.taskButton)
vboxConstraints {
marginTop = 22.0
}
action {
addTask(tasksList, taskInput.text)
}
shortcut("Enter")
}
}
scrollpane {
tasksList = vbox {
vboxConstraints {
marginRight = 20.0
marginLeft = 20.0
marginTop = 20.0
marginBottom = 20.0
}
}
style {
backgroundInsets += box(0.px)
}
}
}
prefHeight = 600.0
}
}
fun addTask (parent: VBox, text: String) {
if (validate()) {
parent.add(vbox {
addClass(Styles.tasks)
text(text)
vboxConstraints {
marginTop = 10.0
marginBottom = 10.0
marginLeft = 20.0
}
setOnMouseClicked {
removeTask(this)
}
tooltip("Click this task to flag as done and remove")
})
taskInput.text = ""
} else {
return
}
}
fun removeTask (child: Node) {
timeline {
keyframe(0.3.seconds) {
keyvalue(child.translateXProperty(), 130, interpolator = Interpolator.EASE_BOTH)
keyvalue(child.opacityProperty(), 0, interpolator = Interpolator.EASE_BOTH)
setOnFinished {
child.removeFromParent()
}
}
}
}
fun validate (): Boolean {
var bol = true
if (taskInput.text == "")
bol = false
return bol
}
}
Juan
08/17/2017, 2:10 PM