From 5e21fa5a0f4927ef397fa173d19f49fa044dd450 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 5 Jun 2017 22:46:30 +0300 Subject: [PATCH] vac to kotlin --- .../PoweredVacuumeterViewConnection.kt | 46 -------- .../readvac/VacuumeterViewConnection.kt | 106 ++++++++++++++---- .../main/resources/fxml/PoweredVacView.fxml | 86 +++++++------- 3 files changed, 124 insertions(+), 114 deletions(-) delete mode 100644 numass-control/vac/src/main/kotlin/inr/numass/control/readvac/PoweredVacuumeterViewConnection.kt diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/PoweredVacuumeterViewConnection.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/PoweredVacuumeterViewConnection.kt deleted file mode 100644 index b669793b..00000000 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/PoweredVacuumeterViewConnection.kt +++ /dev/null @@ -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()) - } 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()) - } -} diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacuumeterViewConnection.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacuumeterViewConnection.kt index 27ef7048..d09cddfa 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacuumeterViewConnection.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacuumeterViewConnection.kt @@ -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>(), 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>(), 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()) } } } diff --git a/numass-control/vac/src/main/resources/fxml/PoweredVacView.fxml b/numass-control/vac/src/main/resources/fxml/PoweredVacView.fxml index 74ffcf30..3751fa01 100644 --- a/numass-control/vac/src/main/resources/fxml/PoweredVacView.fxml +++ b/numass-control/vac/src/main/resources/fxml/PoweredVacView.fxml @@ -9,53 +9,47 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - + + + + + + + + + + + + + + + + +