This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TornadoFX has View, Controller, and Model components, allowing you to separate your code cleanly. | |
class MyApp: View() { | |
// global variables | |
val numCol: Int = 8 | |
// every view has a root component | |
override val root = gridpane { | |
vgap = 15.0 | |
padding = insets(15) | |
for (var i in 1..numCol) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NeighborhoodView: View() { | |
// dependency injection | |
private val controller: NeighborhoodController by inject() | |
// set up neighborhood | |
override val root = gridpane { | |
vgap = 15.0 | |
padding = insets(15) | |
row { | |
add(controller.grassPane()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainView : View("Neighborhood Cat Scheduler") { | |
override val root = stackpane { | |
borderpane { | |
prefHeight = 700.0 | |
prefWidth = 800.0 | |
top(NeighborhoodView::class) | |
left(BottomView::class) | |
} | |
addClass(Styles.main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BottomView: View() { | |
private val controller: BottomViewController by inject() | |
private val model: CatScheduleModel by inject() | |
private var cat: String = "/kitty/kitty1.png" | |
override val root = hbox { | |
tabpane { | |
tab("Monday") { | |
tableview(controller.mondays) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BottomView: View() { | |
private val controller: BottomViewController by inject() | |
private val model: CatScheduleModel by inject() | |
private var cat: String = "/kitty/kitty1.png" | |
private var weekdays = listOf( | |
Pair("Monday", controller.mondays), | |
Pair("Tuesday", controller.tuesdays), | |
Pair("Wednesday", controller.wednesdays), | |
Pair("Thursday", controller.thursdays), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BottomView: View() { | |
private val controller: BottomViewController by inject() | |
private val model: CatScheduleModel by inject() | |
lateinit var avi: StackPane | |
private var weekdays = listOf( | |
Pair("Monday", controller.mondays), | |
Pair("Tuesday", controller.tuesdays), | |
Pair("Wednesday", controller.wednesdays), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creates a new Scope and injects a CatSchedule configured with the selected user into that scope. | |
fun editCatSchedule(catSchedule: CatSchedule) { | |
val catScheduleScope = CatScheduleScope() | |
catScheduleScope.model.item = catSchedule | |
find(Editor::class, scope = catScheduleScope).openModal() | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Editor: Fragment() { | |
// cast scope | |
override val scope = super.scope as CatScheduleScope | |
// extract our view model from the scope | |
private val model = scope.model | |
var ownerNameField : TextField by singleAssign() | |
var catNameField : TextField by singleAssign() | |
var timeField: TextField by singleAssign() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NeighborhoodView: View() { | |
private val controller: NeighborhoodController by inject() | |
// set up neighborhood | |
override val root = stackpane { | |
gridpane { | |
... | |
} | |
pane { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CatSchedule(ownerName: String, catName: String, address: String, | |
time: String, catImage: String) { | |
val ownerNameProperty = SimpleStringProperty(this, "", ownerName) | |
var ownerName by ownerNameProperty | |
val catNameProperty = SimpleStringProperty(this, "", catName) | |
var catName by catNameProperty | |
val addressProperty = SimpleStringProperty(this, "", address) | |
var address by addressProperty |