Numass control room global update

This commit is contained in:
Alexander Nozik 2017-05-27 11:50:11 +03:00
parent c7e460d43d
commit ad958f8f9c
7 changed files with 107 additions and 69 deletions

View File

@ -13,14 +13,11 @@ import javafx.beans.property.SimpleObjectProperty
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import tornadofx.*
import java.util.*
/**
* Created by darksnake on 12-May-17.
*/
class BoardController() : Controller() {
private val serviceLoader = ServiceLoader.load(DeviceViewFactory::class.java);
val devices: ObservableList<DeviceViewConnection<*>> = FXCollections.observableArrayList<DeviceViewConnection<*>>();
val storageProperty = SimpleObjectProperty<Storage>()
@ -61,12 +58,13 @@ class BoardController() : Controller() {
private fun buildDeviceView(context: Context, deviceMeta: Meta): DeviceViewConnection<*> {
context.logger.info("Building device with meta: {}", deviceMeta)
val factory = serviceLoader.find {
it.type == deviceMeta.getString("type")
};
if (factory != null) {
val device = factory.build(context, deviceMeta);
val view = factory.buildView(device);
val factory = context.serviceStream(DeviceViewFactory::class.java)
.filter { it.type == deviceMeta.getString("type") }
.findFirst();
if (factory.isPresent) {
val device = factory.get().build(context, deviceMeta);
val view = factory.get().buildView(device);
device.connect(view, Roles.VIEW_ROLE, Roles.DEVICE_LISTENER_ROLE)
device.init();
return view;
@ -76,7 +74,10 @@ class BoardController() : Controller() {
}
private fun buildStorage(context: Context, meta: Meta): Storage {
val storageMeta = meta.getMeta("storage");
val storageMeta = meta.getMeta("storage").builder
.putValue("readOnly", false)
.putValue("monitor", true)
context.logger.info("Creating storage for server with meta {}", storageMeta)
var storage = StorageFactory.buildStorage(context, storageMeta);

View File

@ -1,8 +1,10 @@
package inr.numass.control
import hep.dataforge.control.devices.Device
import hep.dataforge.control.devices.PortSensor
import hep.dataforge.fx.fragments.FXFragment
import hep.dataforge.fx.fragments.FragmentWindow
import hep.dataforge.storage.filestorage.FileStorage
import inr.numass.control.NumassControlUtils.getDFIcon
import javafx.geometry.Orientation
import javafx.geometry.Pos
@ -22,12 +24,12 @@ class BoardView : View("Numass control board", ImageView(getDFIcon())) {
prefWidth = 200.0
center {
vbox {
hbox {
alignment = Pos.CENTER
//Server pane
titledpane(title = "Server", collapsible = false) {
vgrow = Priority.ALWAYS;
hbox {
alignment = Pos.CENTER_LEFT
prefHeight = 40.0
text("Server") // TODO add fancy style here
separator(Orientation.VERTICAL)
var serverLabel: Hyperlink by singleAssign();
togglebutton("Start") {
isSelected = false
@ -44,41 +46,58 @@ class BoardView : View("Numass control board", ImageView(getDFIcon())) {
}
}
}
text("Started: ") {
paddingHorizontal = 5
}
indicator {
bind(controller.serverManager.isStarted)
}
separator(Orientation.VERTICAL)
text("Address: ")
serverLabel = hyperlink {
action {
hostServices.showDocument(controller.serverManager.link);
}
}
}
separator(Orientation.HORIZONTAL)
hbox {
alignment = Pos.CENTER
}
titledpane(title = "Storage", collapsible = true) {
vgrow = Priority.ALWAYS;
hbox {
alignment = Pos.CENTER_LEFT
prefHeight = 40.0
text("Storage")
separator(Orientation.VERTICAL)
label(stringBinding(controller.storage) {
controller.storage.fullPath
val storage = controller.storage
if (storage is FileStorage) {
"Path: " + storage.dataDir;
} else {
"Name: " + controller.storage.fullPath
}
})
}
}
separator(Orientation.HORIZONTAL)
vbox {
scrollpane(fitToWidth = true, fitToHeight = true) {
vgrow = Priority.ALWAYS;
vbox {
prefHeight = 40.0
bindChildren(controller.devices) { connection ->
titledpane(title = "Device: " + connection.device.name, collapsible = true) {
hbox {
alignment = Pos.CENTER
alignment = Pos.CENTER_LEFT
vgrow = Priority.ALWAYS;
text("Device: " + connection.device.name)
separator(Orientation.VERTICAL)
indicator {
bind(connection, Device.INITIALIZED_STATE)
deviceStateIndicator(connection,Device.INITIALIZED_STATE)
deviceStateIndicator(connection, PortSensor.CONNECTED_STATE)
deviceStateIndicator(connection, "storing")
pane {
hgrow = Priority.ALWAYS
}
togglebutton("View") {
isSelected = false
FragmentWindow(FXFragment.buildFromNode(connection.device.name) { connection.fxNode }).bindTo(this)
}
}
}
val viewButton = togglebutton("View")
FragmentWindow(FXFragment.buildFromNode(connection.device.name) { connection.fxNode }).bindTo(viewButton)
}
}
}

View File

@ -3,6 +3,7 @@ package inr.numass.control
import hep.dataforge.values.Value
import javafx.beans.value.ObservableValue
import javafx.event.EventTarget
import javafx.geometry.Orientation
import javafx.scene.paint.Color
import javafx.scene.paint.Paint
import javafx.scene.shape.Circle
@ -19,7 +20,6 @@ class Indicator(radius: Double = 10.0) : Circle(radius, Color.GRAY) {
init {
stroke = Color.BLACK;
strokeType = StrokeType.INSIDE;
tooltip { }
}
/**
@ -30,11 +30,12 @@ class Indicator(radius: Double = 10.0) : Circle(radius, Color.GRAY) {
throw RuntimeException("Indicator already bound");
} else {
binding = observable;
}
fill = transform(observable.value)
observable.addListener { _, _, value ->
fill = transform(value);
}
}
}
/**
* bind indicator to the boolean value using default colours
@ -80,3 +81,16 @@ fun Indicator.bind(connection: DeviceViewConnection<*>, state: String, transform
}
}
}
/**
* State name + indicator
*/
fun EventTarget.deviceStateIndicator(connection: DeviceViewConnection<*>, state: String, transform: ((Value) -> Paint)? = null) {
if (connection.device.hasState(state)) {
text("${state.toUpperCase()}: ")
indicator {
bind(connection, state, transform);
}
separator(Orientation.VERTICAL)
}
}

View File

@ -1,9 +1,9 @@
package inr.numass.control
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import javafx.stage.Stage
import tornadofx.*
import java.io.File
/**
* Created by darksnake on 19-May-17.
@ -14,7 +14,11 @@ class ServerApp : App(BoardView::class) {
override fun start(stage: Stage) {
NumassControlUtils.getConfig(this).ifPresent {
context = Global.getContext("NUMASS-SERVER");
val libPath = parameters.named.getOrDefault("libPath","../lib");
context = Context
.builder("NUMASS-SERVER")
.classPath(File(libPath).toURI().toURL())
.build()
controller.load(context, it);
}
super.start(stage)

View File

@ -36,7 +36,7 @@ public class MspApp extends NumassControlApplication<MspDevice> {
}
@Override
protected DeviceFactory<MspDevice> getDeviceFactory() {
protected DeviceFactory getDeviceFactory() {
return new MspDeviceFactory();
}

View File

@ -25,7 +25,7 @@ public class ReadVac extends NumassControlApplication<VacCollectorDevice> {
}
@Override
protected DeviceFactory<VacCollectorDevice> getDeviceFactory() {
protected DeviceFactory getDeviceFactory() {
return new VacDeviceFactory();
}

View File

@ -27,7 +27,7 @@ dependencies {
compile 'org.controlsfx:controlsfx:8.40.12'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:'1.1.2-3"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8"
compile "no.tornado:tornadofx:1.7.4"
}