vac to kotlin

This commit is contained in:
Alexander Nozik 2017-06-05 22:46:30 +03:00
parent 04b3dc9fc2
commit 5e21fa5a0f
3 changed files with 124 additions and 114 deletions

View File

@ -1,46 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.control.readvac
import javafx.fxml.FXML
import javafx.fxml.FXMLLoader
import javafx.scene.Node
import org.controlsfx.control.ToggleSwitch
import java.io.IOException
import java.net.URL
import java.util.*
/**
* @author [Alexander Nozik](mailto:altavir@gmail.com)
*/
class PoweredVacuumeterViewConnection : VacuumeterViewConnection() {
@FXML
private val powerSwitch: ToggleSwitch? = null
val component: Node
get() {
if (getNode() == null) {
try {
val loader = FXMLLoader(javaClass.getResource("/fxml/PoweredVacBox.fxml"))
loader.setController(this)
this.setNode(loader.load<T>())
} catch (ex: IOException) {
throw RuntimeException(ex)
}
}
return getNode()
}
fun initialize(location: URL, resources: ResourceBundle) {
super.initialize(location, resources)
getUnitLabel().setText(device.meta().getString("units", "mbar"))
getDeviceNameLabel().setText(device.name)
bindBooleanToState("power", powerSwitch!!.selectedProperty())
}
}

View File

@ -11,12 +11,15 @@ import hep.dataforge.control.devices.Sensor
import hep.dataforge.control.measurements.Measurement
import hep.dataforge.control.measurements.MeasurementListener
import inr.numass.control.DeviceViewConnection
import inr.numass.control.switch
import javafx.application.Platform
import javafx.beans.property.SimpleStringProperty
import javafx.scene.control.Label
import javafx.scene.layout.BorderPane
import javafx.geometry.Insets
import javafx.geometry.Orientation
import javafx.geometry.Pos
import javafx.scene.layout.Priority
import javafx.scene.paint.Color
import org.controlsfx.control.ToggleSwitch
import javafx.scene.text.FontWeight
import tornadofx.*
import java.text.DecimalFormat
import java.time.Instant
@ -29,10 +32,10 @@ import java.time.format.DateTimeFormatter
*/
open class VacuumeterViewConnection : DeviceViewConnection<Sensor<Double>>(), MeasurementListener {
val statusProperty = SimpleStringProperty()
val statusProperty = SimpleStringProperty("")
var status: String by statusProperty
val valueProperty = SimpleStringProperty()
val valueProperty = SimpleStringProperty("---")
var value: String by valueProperty
@ -71,26 +74,85 @@ open class VacuumeterViewConnection : DeviceViewConnection<Sensor<Double>>(), Me
inner class VacView : View("Numass vacuumeter ${device.meta().getString("title", device.name)}") {
override val root: BorderPane by fxml()
override val root = borderpane {
style {
val deviceNameLabel: Label by fxid()
val unitLabel: Label by fxid()
val valueLabel: Label by fxid()
val status: Label by fxid()
val disableButton: ToggleSwitch by fxid()
init {
status.textProperty().bind(statusProperty)
valueLabel.textProperty().bind(valueProperty)
unitLabel.text = device.meta().getString("units", "mbar")
deviceNameLabel.text = device.name
bindBooleanToState(CONNECTED_STATE, disableButton.selectedProperty());
disableButton.selectedProperty().addListener { _, _, newValue ->
if (!newValue) {
valueLabel.text = "---"
}
top {
borderpane {
center {
label(device.name){
style {
fontSize = 18.pt
fontWeight = FontWeight.BOLD
}
}
style {
backgroundColor = multi(Color.LAVENDER)
}
}
right {
switch {
bindBooleanToState(CONNECTED_STATE, selectedProperty());
selectedProperty().addListener { _, _, newValue ->
if (!newValue) {
value = "---"
}
}
}
}
}
}
center {
vbox {
separator(Orientation.HORIZONTAL)
borderpane {
left {
label {
padding = Insets(5.0, 5.0, 5.0, 5.0)
prefHeight = 60.0
alignment = Pos.CENTER_RIGHT
textProperty().bind(valueProperty)
device.meta().optValue("color").ifPresent { colorValue -> textFill = Color.valueOf(colorValue.stringValue()) }
style {
fontSize = 24.pt
fontWeight = FontWeight.BOLD
}
}
}
right {
label {
padding = Insets(5.0, 5.0, 5.0, 5.0)
prefHeight = 60.0
prefWidth = 75.0
alignment = Pos.CENTER_LEFT
text = device.meta().getString("units", "mbar")
style {
fontSize = 24.pt
}
}
}
}
if (device.hasState("power")) {
separator(Orientation.HORIZONTAL)
pane {
minHeight = 30.0
vgrow = Priority.ALWAYS
switch("Power") {
alignment = Pos.CENTER
bindBooleanToState("power", selectedProperty())
}
}
}
separator(Orientation.HORIZONTAL)
}
}
bottom {
label {
padding = Insets(5.0, 5.0, 5.0, 5.0)
textProperty().bind(statusProperty)
}
}
device.meta().optValue("color").ifPresent { colorValue -> valueLabel.textFill = Color.valueOf(colorValue.stringValue()) }
}
}

View File

@ -9,53 +9,47 @@
<stylesheets>
<URL value="@vacstyles.css"/>
</stylesheets>
<children>
<VBox layoutX="50.0" layoutY="6.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<AnchorPane styleClass="namePane">
<Label id="name" fx:id="deviceNameLabel" alignment="CENTER" prefHeight="40.0" text="device Name"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="50.0"
AnchorPane.topAnchor="0.0"/>
<ToggleSwitch fx:id="disableButton" alignment="CENTER" layoutX="130.0" layoutY="10.0"
prefWidth="40.0" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0"
AnchorPane.topAnchor="10.0"/>
</AnchorPane>
<Separator/>
<BorderPane>
<left>
<Label id="pressure" fx:id="valueLabel" alignment="CENTER_RIGHT" minWidth="110.0"
prefHeight="60.0" text="---" BorderPane.alignment="CENTER">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
</padding>
</Label>
</left>
<right>
<Label id="units" fx:id="unitLabel" prefHeight="60.0" prefWidth="75.0" text="mbar"
BorderPane.alignment="CENTER">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
</padding>
</Label>
</right>
</BorderPane>
<Separator/>
<Pane minHeight="30.0" prefHeight="30.0" VBox.vgrow="ALWAYS">
<ToggleSwitch fx:id="powerSwitch" layoutX="58.0" layoutY="5.0" text="Power"/>
</Pane>
<Separator/>
<AnchorPane styleClass="statusPane">
<children>
<Label fx:id="status" maxWidth="200.0" text="Initializing" wrapText="true"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0"/>
</children>
<VBox layoutX="50.0" layoutY="6.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0"
AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<AnchorPane styleClass="namePane">
<Label id="name" fx:id="deviceNameLabel" alignment="CENTER" prefHeight="40.0" text="device Name"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="50.0"
AnchorPane.topAnchor="0.0"/>
<ToggleSwitch fx:id="disableButton" alignment="CENTER" layoutX="130.0" layoutY="10.0"
prefWidth="40.0" AnchorPane.bottomAnchor="10.0" AnchorPane.rightAnchor="10.0"
AnchorPane.topAnchor="10.0"/>
</AnchorPane>
<Separator/>
<BorderPane>
<left>
<Label id="pressure" fx:id="valueLabel" alignment="CENTER_RIGHT" minWidth="110.0"
prefHeight="60.0" text="---" BorderPane.alignment="CENTER">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
</padding>
</AnchorPane>
</children>
</VBox>
</children>
</Label>
</left>
<right>
<Label id="units" fx:id="unitLabel" prefHeight="60.0" prefWidth="75.0" text="mbar"
BorderPane.alignment="CENTER">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
</padding>
</Label>
</right>
</BorderPane>
<Separator/>
<Pane minHeight="30.0" prefHeight="30.0" VBox.vgrow="ALWAYS">
<ToggleSwitch fx:id="powerSwitch" layoutX="58.0" layoutY="5.0" text="Power"/>
</Pane>
<Separator/>
<AnchorPane styleClass="statusPane">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0"/>
</padding>
<Label fx:id="status" maxWidth="200.0" text="Initializing" wrapText="true"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0"/>
</AnchorPane>
</VBox>
</AnchorPane>