Skip to content

Commit 7670f09

Browse files
Basic scafolding in place. Date Cell factories not yet complete.
1 parent 269dc9b commit 7670f09

File tree

4 files changed

+184
-0
lines changed

4 files changed

+184
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
**/
19+
20+
package org.epistatic.app5
21+
22+
import javafx.application.Application
23+
import javafx.fxml.FXMLLoader
24+
import javafx.scene.Scene
25+
import javafx.scene.layout.GridPane
26+
import javafx.stage.Stage
27+
28+
/**
29+
* An Application with multiple controllers and nested FXML
30+
*
31+
* 1) Assigning controllers to FXML at runtime
32+
* 2) Multiple controllers communicating via Events (via Google EventBus)
33+
* 3) Dragging Items from the Desktop
34+
* 4) Controllers can leverage dependency injection, improving testing options
35+
*/
36+
class Main : Application() {
37+
38+
@Throws(Exception::class)
39+
override fun start(primaryStage: Stage) {
40+
val loader = FXMLLoader(javaClass.getResource("/app5/app5.fxml"))
41+
val root = loader.load<GridPane>()
42+
primaryStage.title = "TableView Cell Factories"
43+
primaryStage.scene = Scene(root, 750.0, 550.0)
44+
primaryStage.show()
45+
}
46+
47+
companion object {
48+
@JvmStatic
49+
fun main(args: Array<String>) {
50+
launch(Main::class.java, *args)
51+
}
52+
}
53+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package org.epistatic.app5.controller
2+
3+
import javafx.collections.FXCollections
4+
import javafx.collections.ObservableList
5+
import javafx.fxml.FXML
6+
import javafx.scene.control.Button
7+
import javafx.scene.control.TableColumn
8+
import javafx.scene.control.TableView
9+
import javafx.scene.control.cell.PropertyValueFactory
10+
import javafx.stage.Stage
11+
import org.epistatic.app5.model.DateItem
12+
import java.time.OffsetDateTime
13+
import java.time.ZoneOffset
14+
15+
/**
16+
* Licensed to the Apache Software Foundation (ASF) under one
17+
* or more contributor license agreements. See the NOTICE file
18+
* distributed with this work for additional information
19+
* regarding copyright ownership. The ASF licenses this file
20+
* to you under the Apache License, Version 2.0 (the
21+
* "License"); you may not use this file except in compliance
22+
* with the License. You may obtain a copy of the License at
23+
*
24+
* http://www.apache.org/licenses/LICENSE-2.0
25+
*
26+
* Unless required by applicable law or agreed to in writing,
27+
* software distributed under the License is distributed on an
28+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
29+
* KIND, either express or implied. See the License for the
30+
* specific language governing permissions and limitations
31+
* under the License.
32+
**/
33+
34+
/**
35+
* Controller for app5/app5.fxml. Manages the main UI and all the other controllers
36+
*/
37+
class ApplicationController {
38+
39+
@FXML lateinit var exitButton: Button
40+
@FXML lateinit var dateView: TableView<DateItem>
41+
@FXML lateinit var labelColumn: TableColumn<DateItem, String>
42+
@FXML lateinit var dateStringColumn: TableColumn<DateItem, String>
43+
@FXML lateinit var date2Column: TableColumn<DateItem, OffsetDateTime>
44+
@FXML lateinit var date3Column: TableColumn<DateItem, OffsetDateTime>
45+
46+
val model: ObservableList<DateItem> = FXCollections.observableArrayList<DateItem>()
47+
48+
@FXML
49+
fun initialize() {
50+
dateView.items = model
51+
labelColumn.cellValueFactory = PropertyValueFactory<DateItem, String>("label")
52+
dateStringColumn.cellValueFactory = PropertyValueFactory<DateItem, String>("date1")
53+
date2Column.cellValueFactory = PropertyValueFactory<DateItem, OffsetDateTime>("date2")
54+
date3Column.cellValueFactory = PropertyValueFactory<DateItem, OffsetDateTime>("date3")
55+
56+
addItems()
57+
}
58+
59+
@FXML
60+
fun closeApplication() {
61+
val stage = exitButton.scene.window as Stage
62+
stage.close()
63+
}
64+
65+
/**
66+
* Add items to table
67+
*/
68+
private fun addItems() {
69+
var item = DateItem("Green Tree", createDate(2018, 2, 3), createDate(2018, 4, 12), createDate(2018, 8, 21))
70+
model.add(item)
71+
item = DateItem("Red Car", createDate(2017, 5, 19), createDate(2017, 3, 15), createDate(2017, 12, 21))
72+
model.add(item)
73+
item = DateItem("Blue Ship", createDate(2016, 12, 19), createDate(2016, 6, 2), createDate(2017, 7, 28))
74+
model.add(item)
75+
item = DateItem("Yellow Moon", createDate(1990, 4, 4), createDate(1990, 1, 2), createDate(1990, 3, 11))
76+
model.add(item)
77+
}
78+
79+
80+
private fun createDate(year: Int, month: Int, day: Int): OffsetDateTime {
81+
return OffsetDateTime.of(year, month, day, 14, 30, 0, 0, ZoneOffset.UTC)
82+
}
83+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.epistatic.app5.model
2+
3+
import java.time.OffsetDateTime
4+
5+
data class DateItem(val label:String, val date1:OffsetDateTime, val date2:OffsetDateTime, val date3:OffsetDateTime)

src/main/resources/app5/app5.fxml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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="400.0" prefWidth="600.0" 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" prefWidth="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" prefWidth="75.0" text="Label" />
31+
<TableColumn fx:id="dateStringColumn" prefWidth="75.0" text="Date1" />
32+
<TableColumn fx:id="date2Column" prefWidth="75.0" text="Date2" />
33+
<TableColumn fx:id="date3Column" prefWidth="75.0" text="Date3" />
34+
</columns>
35+
<columnResizePolicy>
36+
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
37+
</columnResizePolicy>
38+
</TableView>
39+
</children>
40+
</AnchorPane>
41+
42+
</children>
43+
</GridPane>

0 commit comments

Comments
 (0)