Skip to content

Commit fe34d85

Browse files
Merge branch 'develop' of github.com:SergeMerzliakov/javafx-app-1 into develop
2 parents 144766f + 6a836aa commit fe34d85

File tree

6 files changed

+61
-7
lines changed

6 files changed

+61
-7
lines changed

src/main/kotlin/org/epistatic/app4/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/app4/controller/DateCellFactory1.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import org.epistatic.app4.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/app4/controller/DateCellFactory2.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import org.epistatic.app4.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/app4/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.app4.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/app4/controller/DateOffsetCellValueFactory.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ import org.epistatic.app4.model.DateItem
88
import java.time.OffsetDateTime
99

1010
/**
11-
* 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
1212
*/
13-
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>> {
1414

1515
override fun call(p: TableColumn.CellDataFeatures<DateItem, OffsetDateTime>): ObservableValue<OffsetDateTime> {
1616
return if (p.value != null) {
17-
ReadOnlyObjectWrapper(p.value.date.plusSeconds(offsetSeconds))
17+
ReadOnlyObjectWrapper(p.value.date.plusDays(offsetDays))
1818
} else {
19-
// only objects have a modified attribute as far as I know now
2019
ReadOnlyObjectWrapper()
2120
}
2221
}

src/main/resources/app5/app5.fxml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.geometry.Insets?>
4+
<?import javafx.scene.control.Button?>
5+
<?import javafx.scene.control.TableColumn?>
6+
<?import javafx.scene.control.TableView?>
7+
<?import javafx.scene.layout.AnchorPane?>
8+
<?import javafx.scene.layout.ColumnConstraints?>
9+
<?import javafx.scene.layout.GridPane?>
10+
<?import javafx.scene.layout.RowConstraints?>
11+
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">
13+
<columnConstraints>
14+
<ColumnConstraints halignment="CENTER" hgrow="ALWAYS" maxWidth="1.7976931348623157E308" minWidth="100.0" prefWidth="100.0" />
15+
</columnConstraints>
16+
<rowConstraints>
17+
<RowConstraints minHeight="50.0" prefHeight="250.0" vgrow="ALWAYS" />
18+
<RowConstraints fillHeight="false" maxHeight="46.0" minHeight="46.0" prefHeight="46.0" valignment="CENTER" vgrow="NEVER" />
19+
</rowConstraints>
20+
<children>
21+
<Button id="exitButton" fx:id="exitButton" cancelButton="true" defaultButton="true" minWidth="80.0" mnemonicParsing="false" onAction="#closeApplication" text="Exit" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
22+
<GridPane.margin>
23+
<Insets bottom="8.0" right="10.0" />
24+
</GridPane.margin>
25+
</Button>
26+
<AnchorPane prefHeight="200.0">
27+
<children>
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">
29+
<columns>
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" />
36+
</columns>
37+
<columnResizePolicy>
38+
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
39+
</columnResizePolicy>
40+
</TableView>
41+
</children>
42+
</AnchorPane>
43+
44+
</children>
45+
</GridPane>

0 commit comments

Comments
 (0)