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,8 +28,7 @@ dependencies {
api(project(":dataforge-gui")) api(project(":dataforge-gui"))
} }
application { val addJvmArgs = listOf(
applicationDefaultJvmArgs = listOf(
"--add-exports=javafx.graphics/com.sun.glass.ui=ALL-UNNAMED", "--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.css=ALL-UNNAMED",
"--add-opens=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED", "--add-opens=javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED",
@ -39,4 +39,27 @@ application {
"--add-opens=javafx.controls/javafx.scene.control.skin=ALL-UNNAMED", "--add-opens=javafx.controls/javafx.scene.control.skin=ALL-UNNAMED",
"--add-exports=javafx.controls/com.sun.javafx.scene.control.inputmap=ALL-UNNAMED", "--add-exports=javafx.controls/com.sun.javafx.scene.control.inputmap=ALL-UNNAMED",
) )
application {
applicationDefaultJvmArgs = addJvmArgs
}
runtime {
addOptions("--strip-debug", "--compress", "2", "--no-header-files", "--no-man-pages")
addModules(
"java.desktop",
"jdk.unsupported",
"java.scripting",
"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,9 +100,14 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
} }
} }
} }
watchedProperty.onChange {
toggleWatch(it)
}
} }
fun getChildren(): ObservableList<Container>? = when (content) { val children: ObservableList<Container>? by lazy {
when (content) {
is Storage -> content.getChildren().map { is Storage -> content.getChildren().map {
buildContainer(it, this) buildContainer(it, this)
}.sortedWith(Comparator.comparing({ it.id }, AlphanumComparator)).asObservable() }.sortedWith(Comparator.comparing({ it.id }, AlphanumComparator)).asObservable()
@ -100,9 +117,15 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
.asObservable() .asObservable()
else -> null else -> null
} }
/* }
is NumassDataLoader -> {
val res = content.points.sortedBy { it.index }.map { buildContainer(it, this) }.toObservable() val hasChildren: Boolean = (content is Storage) || (content is NumassSet)
private var watchJob: Job? = null
private fun toggleWatch(watch: Boolean) {
if (watch) {
if (watchJob != null && content is NumassDataLoader) {
watchJob = app.context.launch(Dispatchers.IO) { watchJob = app.context.launch(Dispatchers.IO) {
val key: WatchKey = content.path.register(watcher!!, ENTRY_CREATE) val key: WatchKey = content.path.register(watcher!!, ENTRY_CREATE)
coroutineContext[Job]?.invokeOnCompletion { coroutineContext[Job]?.invokeOnCompletion {
@ -117,7 +140,7 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
val envelope: Envelope = NumassEnvelopeType.infer(path)?.reader?.read(path) val envelope: Envelope = NumassEnvelopeType.infer(path)?.reader?.read(path)
?: kotlin.error("Can't read point file") ?: kotlin.error("Can't read point file")
val point = NumassDataUtils.read(envelope) val point = NumassDataUtils.read(envelope)
res.add(buildContainer(point, this@Container)) children!!.add(buildContainer(point, this@Container))
} }
} }
} }
@ -126,12 +149,12 @@ class StorageView : View(title = "Numass storage", icon = dfIconView) {
} }
} }
} }
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)
}
}
} }
} }
} }