Skip to content

Commit 11b8d7f

Browse files
Updated formatting and options
1 parent e433487 commit 11b8d7f

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

src/main/kotlin/org/epistatic/app5/controller/ApplicationController.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ class ApplicationController {
6565
dateCustomColumn.cellFactory = DateCellFactory2()
6666

6767
// Offset date by 10 seconds
68-
dateCustomColumn2.cellValueFactory = DateOffsetCellValueFactory(10)
68+
dateCustomColumn2.cellValueFactory = DateOffsetCellValueFactory(40)
6969
dateCustomColumn2.cellFactory = DateCellFactory2()
7070

71-
// Use Lambda Cell Factory
71+
// Use Lambda factories as lambdas
7272
dateLambdaColumn.setCellValueFactory { cell: TableColumn.CellDataFeatures<DateItem, OffsetDateTime> -> ReadOnlyObjectWrapper(cell.value.date) }
7373
dateLambdaColumn.setCellFactory {
7474
object : TableCell<DateItem, OffsetDateTime>() {
@@ -79,6 +79,7 @@ class ApplicationController {
7979
}
8080
}
8181
}
82+
8283
addItems()
8384
}
8485

src/main/kotlin/org/epistatic/app5/controller/DateCellFactory1.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import org.epistatic.app5.model.DateItem
77
import java.time.OffsetDateTime
88
import java.time.format.DateTimeFormatter
99

10+
/**
11+
* Sets cell's text to be a formatted date
12+
*/
1013
class DateCellFactory1 : Callback<TableColumn<DateItem, OffsetDateTime>, TableCell<DateItem, OffsetDateTime>> {
1114

1215
companion object {

src/main/kotlin/org/epistatic/app5/controller/DateCellFactory2.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import org.epistatic.app5.model.DateItem
77
import java.time.OffsetDateTime
88
import java.time.format.DateTimeFormatter
99

10+
/**
11+
* Sets cell's text to be another formatted date
12+
*/
1013
class DateCellFactory2 : Callback<TableColumn<DateItem, OffsetDateTime>, TableCell<DateItem, OffsetDateTime>> {
1114

1215
companion object {

src/main/kotlin/org/epistatic/app5/controller/DateCellValueFactory.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import javafx.util.Callback
77
import org.epistatic.app5.model.DateItem
88
import java.time.OffsetDateTime
99

10+
/**
11+
* Explicitly sets the cell value to the objects date field. Same functionality as:
12+
* PropertyValueFactory<DateItem, OffsetDateTime>("date")
13+
*/
1014
class DateCellValueFactory : Callback<TableColumn.CellDataFeatures<DateItem, OffsetDateTime>, ObservableValue<OffsetDateTime>> {
1115

1216
override fun call(p: TableColumn.CellDataFeatures<DateItem, OffsetDateTime>): ObservableValue<OffsetDateTime> {
1317
return if (p.value != null) {
1418
ReadOnlyObjectWrapper(p.value.date)
1519
} else {
16-
// only objects have a modified attribute as far as I know now
1720
ReadOnlyObjectWrapper()
1821
}
1922
}

src/main/kotlin/org/epistatic/app5/controller/DateOffsetCellValueFactory.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ import javafx.scene.control.TableColumn
66
import javafx.util.Callback
77
import org.epistatic.app5.model.DateItem
88
import java.time.OffsetDateTime
9-
import java.time.ZoneOffset
109

1110
/**
12-
* A Cell Value Factory which uses stateful data to alter the cell value
11+
* A Cell Value Factory which uses stateful data to alter the cells date value by a number of days
1312
*/
14-
class DateOffsetCellValueFactory(private val offsetSeconds: Long) : Callback<TableColumn.CellDataFeatures<DateItem, OffsetDateTime>, ObservableValue<OffsetDateTime>> {
13+
class DateOffsetCellValueFactory(private val offsetDays: Long) : Callback<TableColumn.CellDataFeatures<DateItem, OffsetDateTime>, ObservableValue<OffsetDateTime>> {
1514

1615
override fun call(p: TableColumn.CellDataFeatures<DateItem, OffsetDateTime>): ObservableValue<OffsetDateTime> {
1716
return if (p.value != null) {
18-
ReadOnlyObjectWrapper(p.value.date.plusSeconds(offsetSeconds))
17+
ReadOnlyObjectWrapper(p.value.date.plusDays(offsetDays))
1918
} else {
20-
// only objects have a modified attribute as far as I know now
2119
ReadOnlyObjectWrapper()
2220
}
2321
}

src/main/resources/app5/app5.fxml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<?import javafx.scene.layout.GridPane?>
1010
<?import javafx.scene.layout.RowConstraints?>
1111

12-
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="50" minWidth="150" prefHeight="200.0" prefWidth="800.0" stylesheets="@app5.css" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.epistatic.app5.controller.ApplicationController">
12+
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="700.0" stylesheets="@app5.css" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.epistatic.app5.controller.ApplicationController">
1313
<columnConstraints>
1414
<ColumnConstraints halignment="CENTER" hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="100.0" />
1515
</columnConstraints>
@@ -25,14 +25,14 @@
2525
</Button>
2626
<AnchorPane prefHeight="200.0">
2727
<children>
28-
<TableView fx:id="dateView" prefHeight="200.0" prefWidth="750.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
28+
<TableView fx:id="dateView" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
2929
<columns>
30-
<TableColumn fx:id="labelColumn" prefWidth="55.0" styleClass="date-column" text="Label" />
31-
<TableColumn fx:id="dateStringColumn" prefWidth="60.0" styleClass="date-column" text="dateStringColumn" />
32-
<TableColumn fx:id="dateObjectColumn" prefWidth="60.0" styleClass="date-column" text="dateObjectColumn" />
33-
<TableColumn fx:id="dateCustomColumn" prefWidth="90.0" styleClass="date-column" text="dateCustomColumn" />
34-
<TableColumn fx:id="dateCustomColumn2" prefWidth="90.0" styleClass="date-column" text="dateCustomColumn2" />
35-
<TableColumn fx:id="dateLambdaColumn" prefWidth="90.0" styleClass="date-column" text="dateLambdaColumn" />
30+
<TableColumn fx:id="labelColumn" editable="false" maxWidth="85.0" minWidth="85.0" prefWidth="85.0" styleClass="date-column" text="Label" />
31+
<TableColumn fx:id="dateStringColumn" editable="false" prefWidth="75.0" styleClass="date-column" text="dateStringColumn" />
32+
<TableColumn fx:id="dateObjectColumn" editable="false" prefWidth="75.0" styleClass="date-column" text="dateObjectColumn" />
33+
<TableColumn fx:id="dateCustomColumn" editable="false" prefWidth="75.0" styleClass="date-column" text="dateCustomColumn" />
34+
<TableColumn fx:id="dateCustomColumn2" editable="false" prefWidth="75.0" styleClass="date-column" text="dateCustomColumn2" />
35+
<TableColumn fx:id="dateLambdaColumn" editable="false" prefWidth="75.0" styleClass="date-column" text="dateLambdaColumn" />
3636
</columns>
3737
<columnResizePolicy>
3838
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />

0 commit comments

Comments
 (0)