Skip to content

Commit 144766f

Browse files
removed app4 and replaced with tableview factories demo
1 parent e433487 commit 144766f

File tree

16 files changed

+58
-265
lines changed

16 files changed

+58
-265
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The list of demo apps includes:
1414
* **Application 1** - Basic JavaFX/Kotlin Application
1515
* **Application 2** - Drag and Drop
1616
* **Application 3** - Nested Controllers, Event Based using Google EventBus
17+
* **Application 4** - TableView Cell Value Factories vs Cell Factories
1718

1819

1920
My blog on JavaFx with Kotlin at [https://thickclient.blog/](https://thickclient.blog/)
@@ -115,12 +116,12 @@ Start the application with:
115116

116117
gradlew runApp3
117118

118-
### What's Next ?
119119

120-
Some of things I am thinking of, in no particular order:
121-
* More advanced CSS Styling
122-
* TableColumn CellValueFactories for complex objects
123-
* Using asynchronous events to store application UI state (if you are sick of constantly opening and resizing dialogs)
124-
* TornadoFX
125-
120+
#### Application 4 - TableView Cell Factories vs Cell Value Factories
121+
122+
* Examples of different Cell Value and Cell Factories in Kotlin
123+
* FXML based UI
124+
125+
Start the application with:
126126

127+
gradlew runApp4

build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ task runApp4(type: JavaExec) {
9696
}
9797
}
9898

99+
task runApp5(type: JavaExec) {
100+
group = "Application"
101+
description = "Runs Application 5 - Table View Cell Factories"
102+
classpath sourceSets.main.runtimeClasspath
103+
main = 'org.epistatic.app5.Main'
104+
doFirst {
105+
jvmArgs = [
106+
'--module-path', "${JFX_INSTALL}/lib",
107+
'--add-modules', 'javafx.fxml,javafx.controls'
108+
]
109+
}
110+
}
111+
99112
task collateInstall(type:Copy){
100113
delete "installBuild"
101114
mkdir "installBuild/lib"

src/main/kotlin/org/epistatic/app4/Main.kt

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ import javafx.application.Application
2323
import javafx.fxml.FXMLLoader
2424
import javafx.scene.Scene
2525
import javafx.scene.layout.GridPane
26-
import javafx.scene.layout.Pane
2726
import javafx.stage.Stage
28-
import org.epistatic.app4.controller.Child1Controller
29-
import org.epistatic.app4.controller.NestedController
3027

3128
/**
3229
* An Application with multiple controllers and nested FXML
@@ -38,32 +35,15 @@ import org.epistatic.app4.controller.NestedController
3835
*/
3936
class Main : Application() {
4037

41-
lateinit var controller:NestedController
42-
4338
@Throws(Exception::class)
4439
override fun start(primaryStage: Stage) {
45-
controller = NestedController()
46-
loadChildController(controller)
47-
val root = loadAppController()
48-
primaryStage.title = "Nested Controllers"
40+
val loader = FXMLLoader(javaClass.getResource("/app4/app4.fxml"))
41+
val root = loader.load<GridPane>()
42+
primaryStage.title = "TableView Cell Factories"
4943
primaryStage.scene = Scene(root, 750.0, 550.0)
5044
primaryStage.show()
5145
}
5246

53-
private fun loadAppController(): Pane {
54-
val loader = FXMLLoader(javaClass.getResource("/app4/app4.fxml"))
55-
loader.setController(controller)
56-
return loader.load<GridPane>()
57-
}
58-
59-
private fun loadChildController(parent:NestedController): Pane {
60-
val controller = Child1Controller()
61-
parent.child1Controller = controller
62-
val loader = FXMLLoader(javaClass.getResource("/app4/child1.fxml"))
63-
loader.setController(controller)
64-
return loader.load<GridPane>()
65-
}
66-
6747
companion object {
6848
@JvmStatic
6949
fun main(args: Array<String>) {

src/main/kotlin/org/epistatic/app5/controller/ApplicationController.kt renamed to src/main/kotlin/org/epistatic/app4/controller/ApplicationController.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.epistatic.app5.controller
1+
package org.epistatic.app4.controller
22

33
import javafx.beans.property.ReadOnlyObjectWrapper
44
import javafx.collections.FXCollections
@@ -10,7 +10,7 @@ import javafx.scene.control.TableColumn
1010
import javafx.scene.control.TableView
1111
import javafx.scene.control.cell.PropertyValueFactory
1212
import javafx.stage.Stage
13-
import org.epistatic.app5.model.DateItem
13+
import org.epistatic.app4.model.DateItem
1414
import java.time.OffsetDateTime
1515
import java.time.ZoneOffset
1616

@@ -35,7 +35,7 @@ import java.time.ZoneOffset
3535
**/
3636

3737
/**
38-
* Controller for app5/app5.fxml. Manages the main UI and all the other controllers
38+
* Controller for app5/app4.fxml
3939
*/
4040
class ApplicationController {
4141

src/main/kotlin/org/epistatic/app4/controller/Child1Controller.kt

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/main/kotlin/org/epistatic/app5/controller/DateCellFactory1.kt renamed to src/main/kotlin/org/epistatic/app4/controller/DateCellFactory1.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package org.epistatic.app5.controller
1+
package org.epistatic.app4.controller
22

33
import javafx.scene.control.TableCell
44
import javafx.scene.control.TableColumn
55
import javafx.util.Callback
6-
import org.epistatic.app5.model.DateItem
6+
import org.epistatic.app4.model.DateItem
77
import java.time.OffsetDateTime
88
import java.time.format.DateTimeFormatter
99

src/main/kotlin/org/epistatic/app5/controller/DateCellFactory2.kt renamed to src/main/kotlin/org/epistatic/app4/controller/DateCellFactory2.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
package org.epistatic.app5.controller
1+
package org.epistatic.app4.controller
22

33
import javafx.scene.control.TableCell
44
import javafx.scene.control.TableColumn
55
import javafx.util.Callback
6-
import org.epistatic.app5.model.DateItem
6+
import org.epistatic.app4.model.DateItem
77
import java.time.OffsetDateTime
88
import java.time.format.DateTimeFormatter
99

1010
class DateCellFactory2 : Callback<TableColumn<DateItem, OffsetDateTime>, TableCell<DateItem, OffsetDateTime>> {
1111

1212
companion object {
13-
private val customFormat = DateTimeFormatter.ofPattern("yy-MMM-dd *** HH:mm:ss")
13+
private val customFormat = DateTimeFormatter.ofPattern("MMM-dd-yyyy *** HH:mm:ss")
1414
}
1515

1616
override fun call(col: TableColumn<DateItem, OffsetDateTime>?): TableCell<DateItem, OffsetDateTime> {

src/main/kotlin/org/epistatic/app5/controller/DateCellValueFactory.kt renamed to src/main/kotlin/org/epistatic/app4/controller/DateCellValueFactory.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package org.epistatic.app5.controller
1+
package org.epistatic.app4.controller
22

33
import javafx.beans.property.ReadOnlyObjectWrapper
44
import javafx.beans.value.ObservableValue
55
import javafx.scene.control.TableColumn
66
import javafx.util.Callback
7-
import org.epistatic.app5.model.DateItem
7+
import org.epistatic.app4.model.DateItem
88
import java.time.OffsetDateTime
99

1010
class DateCellValueFactory : Callback<TableColumn.CellDataFeatures<DateItem, OffsetDateTime>, ObservableValue<OffsetDateTime>> {

src/main/kotlin/org/epistatic/app5/controller/DateOffsetCellValueFactory.kt renamed to src/main/kotlin/org/epistatic/app4/controller/DateOffsetCellValueFactory.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package org.epistatic.app5.controller
1+
package org.epistatic.app4.controller
22

33
import javafx.beans.property.ReadOnlyObjectWrapper
44
import javafx.beans.value.ObservableValue
55
import javafx.scene.control.TableColumn
66
import javafx.util.Callback
7-
import org.epistatic.app5.model.DateItem
7+
import org.epistatic.app4.model.DateItem
88
import java.time.OffsetDateTime
9-
import java.time.ZoneOffset
109

1110
/**
1211
* A Cell Value Factory which uses stateful data to alter the cell value

src/main/kotlin/org/epistatic/app4/controller/NestedController.kt

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)