Updating tornadofx coals

This commit is contained in:
Alexander Nozik 2017-10-29 22:26:02 +03:00
parent b4bd8260a6
commit ab5c97252e
7 changed files with 207 additions and 93 deletions

View File

@ -76,7 +76,7 @@ public interface NumassSet extends Named, Metoid, Iterable<NumassPoint>, Provide
* @param voltage * @param voltage
* @return * @return
*/ */
default List<NumassPoint> listPoints(double voltage) { default List<NumassPoint> getPoints(double voltage) {
return getPoints().filter(it -> it.getVoltage() == voltage).collect(Collectors.toList()); return getPoints().filter(it -> it.getVoltage() == voltage).collect(Collectors.toList());
} }

View File

@ -70,6 +70,8 @@ class AmplitudeView(
private val data: ObservableMap<String, NumassPoint> = FXCollections.observableHashMap() private val data: ObservableMap<String, NumassPoint> = FXCollections.observableHashMap()
private val plots: ObservableMap<String, Goal<DataPlot>> = FXCollections.observableHashMap() private val plots: ObservableMap<String, Goal<DataPlot>> = FXCollections.observableHashMap()
val isEmpty = booleanBinding(data){data.isEmpty()}
private val progress = object : DoubleBinding() { private val progress = object : DoubleBinding() {
init { init {
bind(plots) bind(plots)
@ -111,11 +113,11 @@ class AmplitudeView(
/** /**
* Put or replace current plot with name `key` * Put or replace current plot with name `key`
*/ */
fun putOne(key: String, point: NumassPoint) { fun add(key: String, point: NumassPoint) {
data.put(key, point) data.put(key, point)
} }
fun putAll(data: Map<String, NumassPoint>) { fun addAll(data: Map<String, NumassPoint>) {
this.data.putAll(data); this.data.putAll(data);
} }
@ -175,7 +177,7 @@ class AmplitudeView(
data.keys.filter { !map.containsKey(it) }.forEach { data.keys.filter { !map.containsKey(it) }.forEach {
remove(it) remove(it)
} }
this.putAll(map); this.addAll(map);
} }
} }

View File

@ -7,6 +7,8 @@ import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.data.TimePlot import hep.dataforge.plots.data.TimePlot
import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.plots.jfreechart.JFreeChartFrame
import inr.numass.data.api.NumassSet import inr.numass.data.api.NumassSet
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.scene.image.ImageView import javafx.scene.image.ImageView
import tornadofx.* import tornadofx.*
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
@ -28,18 +30,21 @@ class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon))
center = PlotContainer(frame).root center = PlotContainer(frame).root
} }
private val data: ObservableList<NumassSet> = FXCollections.observableArrayList()
val isEmpty = booleanBinding(data) { data.isEmpty() }
fun update(vararg sets: NumassSet) { init {
data.onChange { change ->
frame.plots.clear() frame.plots.clear()
container.sideBarExpanded = false container.sideBarExpanded = false
val progress = AtomicInteger(0); val progress = AtomicInteger(0);
runLater { container.progress = -1.0 } runLater { container.progress = -1.0 }
sets.forEach { data -> change.list.forEach { data ->
runAsync { runAsync {
val res = data.hvData val res = data.hvData
runLater { container.progress = progress.incrementAndGet().toDouble() / sets.size } runLater { container.progress = progress.incrementAndGet().toDouble() / change.list.size }
res res
} ui { hvData -> } ui { hvData ->
hvData.ifPresent { hvData.ifPresent {
@ -63,4 +68,20 @@ class HVView : View(title = "High voltage time plot", icon = ImageView(dfIcon))
} }
} }
} }
}
fun update(vararg sets: NumassSet) {
data.setAll(*sets)
}
fun add(set: NumassSet) {
this.data.add(set)
}
fun remove(set: NumassSet) {
this.data.remove(set);
}
} }

View File

@ -14,6 +14,9 @@ import inr.numass.data.api.NumassAnalyzer
import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassPoint
import inr.numass.data.api.NumassSet import inr.numass.data.api.NumassSet
import javafx.beans.property.SimpleIntegerProperty import javafx.beans.property.SimpleIntegerProperty
import javafx.collections.FXCollections
import javafx.collections.MapChangeListener
import javafx.collections.ObservableMap
import javafx.geometry.Insets import javafx.geometry.Insets
import javafx.geometry.Orientation import javafx.geometry.Orientation
import javafx.scene.image.ImageView import javafx.scene.image.ImageView
@ -55,7 +58,8 @@ class SpectrumView(
private var upChannel by upChannelProperty private var upChannel by upChannelProperty
private val data: MutableMap<String, NumassSet> = HashMap() private val data: ObservableMap<String, NumassSet> = FXCollections.observableHashMap();
val isEmpty = booleanBinding(data) { data.isEmpty() }
/* /*
<BorderPane fx:id="spectrumPlotPane" prefHeight="200.0" prefWidth="200.0" <BorderPane fx:id="spectrumPlotPane" prefHeight="200.0" prefWidth="200.0"
@ -135,6 +139,16 @@ class SpectrumView(
center = container.root center = container.root
} }
init {
data.addListener { change: MapChangeListener.Change<out String, out NumassSet> ->
if (change.wasRemoved()) {
frame.remove(change.key);
}
updateView()
}
}
private fun getSpectrum(point: NumassPoint): Table { private fun getSpectrum(point: NumassPoint): Table {
return cache.computeIfAbsent(point) { analyzer.getSpectrum(point, Meta.empty()) } return cache.computeIfAbsent(point) { analyzer.getSpectrum(point, Meta.empty()) }
@ -173,15 +187,11 @@ class SpectrumView(
} }
} }
fun update(map: Map<String, NumassSet>) { fun add(key: String, value: NumassSet) {
synchronized(data) { data.put(key, NumassDataCache(value))
//Remove obsolete keys
data.keys.filter { !map.containsKey(it) }.forEach {
data.remove(it)
frame.remove(it);
}
this.data.putAll(map.mapValues { NumassDataCache(it.value) });
updateView()
} }
fun remove(key: String) {
data.remove(key)
} }
} }

View File

@ -5,16 +5,19 @@ import hep.dataforge.context.Global
import hep.dataforge.exceptions.StorageException import hep.dataforge.exceptions.StorageException
import hep.dataforge.kodex.fx.dfIcon import hep.dataforge.kodex.fx.dfIcon
import hep.dataforge.kodex.fx.runGoal import hep.dataforge.kodex.fx.runGoal
import hep.dataforge.storage.api.Loader
import hep.dataforge.storage.api.Storage import hep.dataforge.storage.api.Storage
import hep.dataforge.storage.filestorage.FileStorageFactory import hep.dataforge.storage.filestorage.FileStorageFactory
import inr.numass.NumassProperties import inr.numass.NumassProperties
import inr.numass.data.api.NumassPoint
import inr.numass.data.api.NumassSet
import inr.numass.data.storage.NumassDataLoader
import inr.numass.data.storage.NumassStorage import inr.numass.data.storage.NumassStorage
import javafx.application.Platform import javafx.application.Platform
import javafx.beans.property.SimpleObjectProperty import javafx.beans.property.SimpleObjectProperty
import javafx.beans.property.SimpleStringProperty import javafx.beans.property.SimpleStringProperty
import javafx.collections.FXCollections
import javafx.collections.ObservableList
import javafx.geometry.Insets import javafx.geometry.Insets
import javafx.scene.control.TreeItem
import javafx.scene.image.ImageView import javafx.scene.image.ImageView
import javafx.scene.layout.Priority import javafx.scene.layout.Priority
import javafx.scene.text.Font import javafx.scene.text.Font
@ -23,22 +26,26 @@ import org.controlsfx.control.StatusBar
import tornadofx.* import tornadofx.*
import java.io.File import java.io.File
import java.net.URI import java.net.URI
import kotlin.streams.toList
class StorageView : View(title = "Numass storage", icon = ImageView(dfIcon)) { class StorageView(private val context: Context = Global.instance()) : View(title = "Numass storage", icon = ImageView(dfIcon)) {
val selected: ObservableList<Any> = FXCollections.observableArrayList();
private val context: Context
get() = Global.instance()
val storageProperty = SimpleObjectProperty<Storage>() val storageProperty = SimpleObjectProperty<Storage>()
var storage by storageProperty var storage by storageProperty
val storageNameProperty = SimpleStringProperty("") private val storageNameProperty = SimpleStringProperty("")
var storageName by storageNameProperty private var storageName by storageNameProperty
val statusBar = StatusBar(); private val statusBar = StatusBar();
private val ampView: AmplitudeView by inject();
private val spectrumView: SpectrumView by inject();
private val hvView: HVView by inject();
private val scView: SlowControlView by inject();
private data class NamedPoint(val id: String, val point: NumassPoint)
override val root = borderpane { override val root = borderpane {
top { top {
@ -67,7 +74,6 @@ class StorageView : View(title = "Numass storage", icon = ImageView(dfIcon)) {
} }
} }
} }
}
label(storageNameProperty) { label(storageNameProperty) {
padding = Insets(0.0, 0.0, 0.0, 10.0); padding = Insets(0.0, 0.0, 0.0, 10.0);
font = Font.font("System Bold", 13.0); font = Font.font("System Bold", 13.0);
@ -79,13 +85,73 @@ class StorageView : View(title = "Numass storage", icon = ImageView(dfIcon)) {
} }
} }
}
center { center {
splitpane { splitpane {
// treetableview { treeview<Any> {
// storageProperty.onChange {
// } root = TreeItem(it)
populate { parent ->
val value = parent.value
when (value) {
is Storage -> value.shelves() + value.loaders()
is NumassSet -> value.points.map { point -> NamedPoint("${getSetName(value)}/${point.voltage}", point) }.toList()
else -> null
}
}
}
cellFormat { value ->
when (value) {
is Storage -> text = value.name
is NumassSet -> {
text = null
graphic = checkbox {
text = value.name
val setName = getSetName(value)
selectedProperty().onChange { selected ->
if (selected) {
spectrumView.add(setName, value)
hvView.add(value)
} else {
spectrumView.remove(setName)
hvView.remove(value)
}
}
}
}
is NamedPoint -> {
text = null
graphic = checkbox {
text = value.id
selectedProperty().onChange { selected ->
if (selected) {
ampView.add(value.id, value.point)
} else {
ampView.remove(id)
}
}
}
}
else -> {
text = (value as Loader).name
}
}
}
}
tabpane { tabpane {
tab("Amplitude spectra", ampView.root) {
isClosable = false
visibleWhen(ampView.isEmpty.not())
}
tab("HV", hvView.root) {
isClosable = false
visibleWhen(hvView.isEmpty.not())
}
tab("Numass spectra", spectrumView.root) {
isClosable = false
visibleWhen(spectrumView.isEmpty.not())
}
} }
setDividerPosition(0, 0.3); setDividerPosition(0, 0.3);
} }
@ -96,36 +162,46 @@ class StorageView : View(title = "Numass storage", icon = ImageView(dfIcon)) {
} }
private fun getSetName(value: NumassSet): String {
return if (value is NumassDataLoader) {
value.path
} else {
value.name
}
}
private fun loadDirectory(path: URI) { private fun loadDirectory(path: URI) {
runGoal("loadDirectory[$path]") { runGoal("loadDirectory[$path]") {
updateTitle("Load storage ($path)") title = "Load storage ($path)"
updateProgress(-1.0, -1.0); progress = -1.0
updateMessage("Building numass storage tree...") message = "Building numass storage tree..."
val root = NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true)); val root = NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true));
setRootStorage(root) setRootStorage(root)
Platform.runLater { storageName = "Storage: " + path } Platform.runLater { storageName = "Storage: " + path }
updateProgress(1.0, 1.0) progress = 1.0
} }
} }
fun setRootStorage(root: Storage) { fun setRootStorage(root: Storage) {
runGoal("loadStorage[${root.name}]") { runGoal("loadStorage[${root.name}]") {
updateTitle("Fill data to UI (" + root.name + ")") title = "Fill data to UI (" + root.name + ")"
updateProgress(-1.0, 1.0) progress = -1.0
Platform.runLater { statusBar.progress = -1.0 } runLater { statusBar.progress = -1.0 }
updateMessage("Loading numass storage tree...") message = "Loading numass storage tree..."
runLater {
try { try {
storageProperty.set(root) storageProperty.set(root)
} catch (ex: StorageException) { } catch (ex: StorageException) {
context.logger.error("Could not load the storage", ex); context.logger.error("Could not load the storage", ex);
} }
}
// callback.setProgress(1, 1); // callback.setProgress(1, 1);
Platform.runLater { statusBar.progress = 0.0 } runLater { statusBar.progress = 0.0 }
updateMessage("Numass storage tree loaded.") message = "Numass storage tree loaded."
updateProgress(1.0, 1.0) progress = 1.0
} }
} }
} }

View File

@ -15,9 +15,9 @@ import java.io.File
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import java.util.stream.Collectors import java.util.stream.Collectors
class ViewerTestApp : App(ViewerTest::class) class ViewerComponentsTestApp : App(ViewerComponentsTest::class)
class ViewerTest : View(title = "Numass viewer test", icon = ImageView(dfIcon)) { class ViewerComponentsTest : View(title = "Numass viewer test", icon = ImageView(dfIcon)) {
//val rootDir = File("D:\\Work\\Numass\\data\\2017_05\\Fill_2") //val rootDir = File("D:\\Work\\Numass\\data\\2017_05\\Fill_2")
@ -45,27 +45,21 @@ class ViewerTest : View(title = "Numass viewer test", icon = ImageView(dfIcon))
} }
center { center {
tabpane { tabpane {
tab("amplitude") { tab("amplitude", amp.root)
content = amp.root tab("spectrum", sp.root)
} tab("hv", hv.root)
tab("spectrum") {
content = sp.root
}
tab("hv") {
content = hv.root
}
} }
} }
} }
fun update(set: NumassSet) { fun update(set: NumassSet) {
amp.setAll(set.points.filter { it.voltage != 16000.0 }.collect(Collectors.toMap({ "point_${it.voltage}" }, { it }))); amp.setAll(set.points.filter { it.voltage != 16000.0 }.collect(Collectors.toMap({ "point_${it.voltage}" }, { it })));
sp.update(mapOf("test" to set)); sp.add("test", set);
hv.update(set) hv.update(set)
} }
} }
fun main(args: Array<String>) { fun main(args: Array<String>) {
Application.launch(ViewerTestApp::class.java, *args); Application.launch(ViewerComponentsTestApp::class.java, *args);
} }

View File

@ -0,0 +1,11 @@
package inr.numass.viewer.test
import inr.numass.viewer.StorageView
import javafx.application.Application
import tornadofx.*
class ViewerTestApp : App(StorageView::class)
fun main(args: Array<String>) {
Application.launch(ViewerTestApp::class.java, *args);
}