Updating tornadofx coals
This commit is contained in:
parent
b4bd8260a6
commit
ab5c97252e
@ -76,7 +76,7 @@ public interface NumassSet extends Named, Metoid, Iterable<NumassPoint>, Provide
|
||||
* @param voltage
|
||||
* @return
|
||||
*/
|
||||
default List<NumassPoint> listPoints(double voltage) {
|
||||
default List<NumassPoint> getPoints(double voltage) {
|
||||
return getPoints().filter(it -> it.getVoltage() == voltage).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,8 @@ class AmplitudeView(
|
||||
private val data: ObservableMap<String, NumassPoint> = FXCollections.observableHashMap()
|
||||
private val plots: ObservableMap<String, Goal<DataPlot>> = FXCollections.observableHashMap()
|
||||
|
||||
val isEmpty = booleanBinding(data){data.isEmpty()}
|
||||
|
||||
private val progress = object : DoubleBinding() {
|
||||
init {
|
||||
bind(plots)
|
||||
@ -111,11 +113,11 @@ class AmplitudeView(
|
||||
/**
|
||||
* Put or replace current plot with name `key`
|
||||
*/
|
||||
fun putOne(key: String, point: NumassPoint) {
|
||||
fun add(key: String, point: NumassPoint) {
|
||||
data.put(key, point)
|
||||
}
|
||||
|
||||
fun putAll(data: Map<String, NumassPoint>) {
|
||||
fun addAll(data: Map<String, NumassPoint>) {
|
||||
this.data.putAll(data);
|
||||
}
|
||||
|
||||
@ -175,7 +177,7 @@ class AmplitudeView(
|
||||
data.keys.filter { !map.containsKey(it) }.forEach {
|
||||
remove(it)
|
||||
}
|
||||
this.putAll(map);
|
||||
this.addAll(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import hep.dataforge.plots.PlotFrame
|
||||
import hep.dataforge.plots.data.TimePlot
|
||||
import hep.dataforge.plots.jfreechart.JFreeChartFrame
|
||||
import inr.numass.data.api.NumassSet
|
||||
import javafx.collections.FXCollections
|
||||
import javafx.collections.ObservableList
|
||||
import javafx.scene.image.ImageView
|
||||
import tornadofx.*
|
||||
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
|
||||
}
|
||||
|
||||
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()
|
||||
container.sideBarExpanded = false
|
||||
|
||||
val progress = AtomicInteger(0);
|
||||
runLater { container.progress = -1.0 }
|
||||
|
||||
sets.forEach { data ->
|
||||
change.list.forEach { data ->
|
||||
runAsync {
|
||||
val res = data.hvData
|
||||
runLater { container.progress = progress.incrementAndGet().toDouble() / sets.size }
|
||||
runLater { container.progress = progress.incrementAndGet().toDouble() / change.list.size }
|
||||
res
|
||||
} ui { hvData ->
|
||||
hvData.ifPresent {
|
||||
@ -64,3 +69,19 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -14,6 +14,9 @@ import inr.numass.data.api.NumassAnalyzer
|
||||
import inr.numass.data.api.NumassPoint
|
||||
import inr.numass.data.api.NumassSet
|
||||
import javafx.beans.property.SimpleIntegerProperty
|
||||
import javafx.collections.FXCollections
|
||||
import javafx.collections.MapChangeListener
|
||||
import javafx.collections.ObservableMap
|
||||
import javafx.geometry.Insets
|
||||
import javafx.geometry.Orientation
|
||||
import javafx.scene.image.ImageView
|
||||
@ -55,7 +58,8 @@ class SpectrumView(
|
||||
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"
|
||||
@ -135,6 +139,16 @@ class SpectrumView(
|
||||
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 {
|
||||
return cache.computeIfAbsent(point) { analyzer.getSpectrum(point, Meta.empty()) }
|
||||
|
||||
@ -173,15 +187,11 @@ class SpectrumView(
|
||||
}
|
||||
}
|
||||
|
||||
fun update(map: Map<String, NumassSet>) {
|
||||
synchronized(data) {
|
||||
//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 add(key: String, value: NumassSet) {
|
||||
data.put(key, NumassDataCache(value))
|
||||
}
|
||||
|
||||
fun remove(key: String) {
|
||||
data.remove(key)
|
||||
}
|
||||
}
|
||||
|
@ -5,16 +5,19 @@ import hep.dataforge.context.Global
|
||||
import hep.dataforge.exceptions.StorageException
|
||||
import hep.dataforge.kodex.fx.dfIcon
|
||||
import hep.dataforge.kodex.fx.runGoal
|
||||
import hep.dataforge.storage.api.Loader
|
||||
import hep.dataforge.storage.api.Storage
|
||||
import hep.dataforge.storage.filestorage.FileStorageFactory
|
||||
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 javafx.application.Platform
|
||||
import javafx.beans.property.SimpleObjectProperty
|
||||
import javafx.beans.property.SimpleStringProperty
|
||||
import javafx.collections.FXCollections
|
||||
import javafx.collections.ObservableList
|
||||
import javafx.geometry.Insets
|
||||
import javafx.scene.control.TreeItem
|
||||
import javafx.scene.image.ImageView
|
||||
import javafx.scene.layout.Priority
|
||||
import javafx.scene.text.Font
|
||||
@ -23,22 +26,26 @@ import org.controlsfx.control.StatusBar
|
||||
import tornadofx.*
|
||||
import java.io.File
|
||||
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>()
|
||||
var storage by storageProperty
|
||||
|
||||
|
||||
val storageNameProperty = SimpleStringProperty("")
|
||||
var storageName by storageNameProperty
|
||||
private val storageNameProperty = SimpleStringProperty("")
|
||||
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 {
|
||||
top {
|
||||
@ -67,7 +74,6 @@ class StorageView : View(title = "Numass storage", icon = ImageView(dfIcon)) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
label(storageNameProperty) {
|
||||
padding = Insets(0.0, 0.0, 0.0, 10.0);
|
||||
font = Font.font("System Bold", 13.0);
|
||||
@ -79,13 +85,73 @@ class StorageView : View(title = "Numass storage", icon = ImageView(dfIcon)) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
center {
|
||||
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 {
|
||||
|
||||
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);
|
||||
}
|
||||
@ -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) {
|
||||
runGoal("loadDirectory[$path]") {
|
||||
updateTitle("Load storage ($path)")
|
||||
updateProgress(-1.0, -1.0);
|
||||
updateMessage("Building numass storage tree...")
|
||||
title = "Load storage ($path)"
|
||||
progress = -1.0
|
||||
message = "Building numass storage tree..."
|
||||
val root = NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true));
|
||||
setRootStorage(root)
|
||||
Platform.runLater { storageName = "Storage: " + path }
|
||||
updateProgress(1.0, 1.0)
|
||||
progress = 1.0
|
||||
}
|
||||
}
|
||||
|
||||
fun setRootStorage(root: Storage) {
|
||||
runGoal("loadStorage[${root.name}]") {
|
||||
updateTitle("Fill data to UI (" + root.name + ")")
|
||||
updateProgress(-1.0, 1.0)
|
||||
Platform.runLater { statusBar.progress = -1.0 }
|
||||
title = "Fill data to UI (" + root.name + ")"
|
||||
progress = -1.0
|
||||
runLater { statusBar.progress = -1.0 }
|
||||
|
||||
updateMessage("Loading numass storage tree...")
|
||||
message = "Loading numass storage tree..."
|
||||
|
||||
runLater {
|
||||
try {
|
||||
storageProperty.set(root)
|
||||
} catch (ex: StorageException) {
|
||||
context.logger.error("Could not load the storage", ex);
|
||||
}
|
||||
}
|
||||
|
||||
// callback.setProgress(1, 1);
|
||||
Platform.runLater { statusBar.progress = 0.0 }
|
||||
updateMessage("Numass storage tree loaded.")
|
||||
updateProgress(1.0, 1.0)
|
||||
runLater { statusBar.progress = 0.0 }
|
||||
message = "Numass storage tree loaded."
|
||||
progress = 1.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ import java.io.File
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
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")
|
||||
|
||||
@ -45,27 +45,21 @@ class ViewerTest : View(title = "Numass viewer test", icon = ImageView(dfIcon))
|
||||
}
|
||||
center {
|
||||
tabpane {
|
||||
tab("amplitude") {
|
||||
content = amp.root
|
||||
}
|
||||
tab("spectrum") {
|
||||
content = sp.root
|
||||
}
|
||||
tab("hv") {
|
||||
content = hv.root
|
||||
}
|
||||
tab("amplitude", amp.root)
|
||||
tab("spectrum", sp.root)
|
||||
tab("hv", hv.root)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun update(set: NumassSet) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Application.launch(ViewerTestApp::class.java, *args);
|
||||
Application.launch(ViewerComponentsTestApp::class.java, *args);
|
||||
}
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user