Image packaging for viewer

This commit is contained in:
Alexander Nozik 2021-11-14 21:30:31 +03:00
parent 35801d82fc
commit f376fa65a4
3 changed files with 99 additions and 46 deletions

View File

@ -12,7 +12,9 @@ description = "A tornadofx based kotlin library"
dependencies { dependencies {
api(project(":dataforge-plots")) api(project(":dataforge-plots"))
api(project(":dataforge-gui:dataforge-html")) api(project(":dataforge-gui:dataforge-html"))
api("no.tornado:tornadofx:1.7.20") api("no.tornado:tornadofx:1.7.20"){
exclude("org.jetbrains.kotlin")
}
api("org.controlsfx:controlsfx:11.1.0") api("org.controlsfx:controlsfx:11.1.0")
api("no.tornado:tornadofx-controlsfx:0.1.1") api("no.tornado:tornadofx-controlsfx:0.1.1")
api("org.fxmisc.richtext:richtextfx:0.10.7") api("org.fxmisc.richtext:richtextfx:0.10.7")

View File

@ -1,6 +1,7 @@
plugins { plugins {
kotlin("jvm") kotlin("jvm")
id("org.openjfx.javafxplugin") id("org.openjfx.javafxplugin")
id("org.beryx.runtime") version "1.12.7"
application application
} }
@ -27,16 +28,38 @@ dependencies {
api(project(":dataforge-gui")) api(project(":dataforge-gui"))
} }
val addJvmArgs = listOf(
"--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED",
"--add-opens=javafx.graphics/com.sun.javafx.css=ALL-UNNAMED",
"--add-opens=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED",
"--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED",
"--add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED",
"--add-opens=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED",
"--add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED",
"--add-opens=javafx.controls/javafx.scene.control.skin=ALL-UNNAMED",
"--add-exports=javafx.controls/com.sun.javafx.scene.control.inputmap=ALL-UNNAMED",
)
application { application {
applicationDefaultJvmArgs = listOf( applicationDefaultJvmArgs = addJvmArgs
"--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED", }
"--add-opens=javafx.graphics/com.sun.javafx.css=ALL-UNNAMED",
"--add-opens=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED", runtime {
"--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=ALL-UNNAMED", addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")
"--add-opens=javafx.graphics/javafx.scene=ALL-UNNAMED", addModules(
"--add-opens=javafx.controls/com.sun.javafx.scene.control=ALL-UNNAMED", "java.desktop",
"--add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=ALL-UNNAMED", "jdk.unsupported",
"--add-opens=javafx.controls/javafx.scene.control.skin=ALL-UNNAMED", "java.scripting",
"--add-exports=javafx.controls/com.sun.javafx.scene.control.inputmap=ALL-UNNAMED", "java.logging",
"java.xml",
"javafx.graphics",
"javafx.controls"
) )
jpackage {
jvmArgs = addJvmArgs
imageOptions = listOf("--linux-deb-maintainer nozik.aa@mipt.ru", "--linux-menu-group Science")
}
launcher {
jvmArgs = addJvmArgs
}
} }

View File

@ -2,6 +2,7 @@ package inr.numass.viewer
import hep.dataforge.fx.dfIconView import hep.dataforge.fx.dfIconView
import hep.dataforge.fx.meta.MetaViewer import hep.dataforge.fx.meta.MetaViewer
import hep.dataforge.io.envelopes.Envelope
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.meta.Metoid import hep.dataforge.meta.Metoid
import hep.dataforge.names.AlphanumComparator import hep.dataforge.names.AlphanumComparator
@ -9,6 +10,8 @@ import hep.dataforge.storage.Storage
import hep.dataforge.storage.files.FileStorage import hep.dataforge.storage.files.FileStorage
import hep.dataforge.storage.files.FileTableLoader import hep.dataforge.storage.files.FileTableLoader
import hep.dataforge.storage.tables.TableLoader import hep.dataforge.storage.tables.TableLoader
import inr.numass.data.NumassDataUtils
import inr.numass.data.NumassEnvelopeType
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 inr.numass.data.storage.NumassDataLoader import inr.numass.data.storage.NumassDataLoader
@ -17,7 +20,14 @@ import javafx.beans.property.SimpleObjectProperty
import javafx.collections.ObservableList import javafx.collections.ObservableList
import javafx.scene.control.ContextMenu import javafx.scene.control.ContextMenu
import javafx.scene.control.TreeItem import javafx.scene.control.TreeItem
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import tornadofx.* import tornadofx.*
import java.nio.file.Path
import java.nio.file.StandardWatchEventKinds.ENTRY_CREATE
import java.nio.file.WatchKey
import java.nio.file.WatchService import java.nio.file.WatchService
@ -58,6 +68,8 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
} }
} }
val watchedProperty = SimpleBooleanProperty(false)
init { init {
checkedProperty.onChange { selected -> checkedProperty.onChange { selected ->
when (content) { when (content) {
@ -88,50 +100,61 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
} }
} }
} }
watchedProperty.onChange {
toggleWatch(it)
}
} }
fun getChildren(): ObservableList<Container>? = when (content) { val children: ObservableList<Container>? by lazy {
is Storage -> content.getChildren().map { when (content) {
buildContainer(it, this) is Storage -> content.getChildren().map {
}.sortedWith(Comparator.comparing({ it.id }, AlphanumComparator)).asObservable() buildContainer(it, this)
is NumassSet -> content.points }.sortedWith(Comparator.comparing({ it.id }, AlphanumComparator)).asObservable()
.sortedBy { it.index } is NumassSet -> content.points
.map { buildContainer(it, this) } .sortedBy { it.index }
.asObservable() .map { buildContainer(it, this) }
else -> null .asObservable()
else -> null
}
} }
/*
is NumassDataLoader -> { val hasChildren: Boolean = (content is Storage) || (content is NumassSet)
val res = content.points.sortedBy { it.index }.map { buildContainer(it, this) }.toObservable()
watchJob = app.context.launch(Dispatchers.IO) { private var watchJob: Job? = null
val key: WatchKey = content.path.register(watcher!!, ENTRY_CREATE)
coroutineContext[Job]?.invokeOnCompletion { private fun toggleWatch(watch: Boolean) {
key.cancel() if (watch) {
} if (watchJob != null && content is NumassDataLoader) {
while (watcher != null && isActive) { watchJob = app.context.launch(Dispatchers.IO) {
try { val key: WatchKey = content.path.register(watcher!!, ENTRY_CREATE)
key.pollEvents().forEach { event -> coroutineContext[Job]?.invokeOnCompletion {
if (event.kind() == ENTRY_CREATE) { key.cancel()
val path: Path = event.context() as Path }
if (path.fileName.toString().startsWith(NumassDataLoader.POINT_FRAGMENT_NAME)) { while (watcher != null && isActive) {
val envelope: Envelope = NumassEnvelopeType.infer(path)?.reader?.read(path) try {
?: kotlin.error("Can't read point file") key.pollEvents().forEach { event ->
val point = NumassDataUtils.read(envelope) if (event.kind() == ENTRY_CREATE) {
res.add(buildContainer(point, this@Container)) val path: Path = event.context() as Path
if (path.fileName.toString().startsWith(NumassDataLoader.POINT_FRAGMENT_NAME)) {
val envelope: Envelope = NumassEnvelopeType.infer(path)?.reader?.read(path)
?: kotlin.error("Can't read point file")
val point = NumassDataUtils.read(envelope)
children!!.add(buildContainer(point, this@Container))
}
} }
} }
} catch (x: Throwable) {
app.context.logger.error("Error during dynamic point read", x)
} }
} catch (x: Throwable) {
app.context.logger.error("Error during dynamic point read", x)
} }
} }
} }
res } else {
watchJob?.cancel()
watchJob = null
} }
*/ }
val hasChildren: Boolean = (content is Storage) || (content is NumassSet)
} }
@ -146,7 +169,7 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
lazyPopulate(leafCheck = { lazyPopulate(leafCheck = {
!it.value.hasChildren !it.value.hasChildren
}) { }) {
it.value.getChildren() it.value.children
} }
watcher?.close() watcher?.close()
watcher = if (storage is FileStorage) { watcher = if (storage is FileStorage) {
@ -196,6 +219,11 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
value.infoView.openModal(escapeClosesWindow = true) value.infoView.openModal(escapeClosesWindow = true)
} }
} }
if(value.content is NumassDataLoader) {
checkmenuitem("Watch") {
selectedProperty().bindBidirectional(value.watchedProperty)
}
}
} }
} }
} }