diff --git a/numass-core/src/main/java/inr/numass/data/NumassPoint.java b/numass-core/src/main/java/inr/numass/data/NumassPoint.java index 9367eec0..24fb067b 100644 --- a/numass-core/src/main/java/inr/numass/data/NumassPoint.java +++ b/numass-core/src/main/java/inr/numass/data/NumassPoint.java @@ -37,7 +37,7 @@ public interface NumassPoint { int i = 0; - while (i < RawNMPoint.MAX_CHANEL - binning) { + while (i < getMaxChannel() - binning) { int start = i; double sum = 0; while (i < start + binning) { @@ -60,4 +60,8 @@ public interface NumassPoint { double getVoltage(); int[] getSpectrum(); + + default int getMaxChannel(){ + return getSpectrum().length - 1; + } } diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt index 62fc377f..929ff1dd 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt @@ -18,6 +18,7 @@ import javafx.application.Platform import javafx.beans.property.SimpleObjectProperty import javafx.geometry.Insets import javafx.scene.control.* +import javafx.scene.control.TreeTableView.CONSTRAINED_RESIZE_POLICY import javafx.scene.input.MouseEvent import javafx.scene.layout.AnchorPane import javafx.scene.layout.BorderPane @@ -84,16 +85,18 @@ class MainView : View() { } } - storageProperty.addListener { ob, old, value -> + columnResizePolicy = CONSTRAINED_RESIZE_POLICY + + storageProperty.addListener { _, _, value -> if (value != null) { Platform.runLater { root = TreeItem(Item(value)); populate { parent -> - val value = parent.value.content; - if (value is Storage) { + val storage = parent.value.content; + if (storage is Storage) { //TODO add legacy loaders here? - value.shelves().map(::Item) + value.loaders().map(::Item) + storage.shelves().map(::Item) + storage.loaders().map(::Item) } else { null } @@ -216,7 +219,11 @@ class MainView : View() { fun getTime(): String { if (content is NumassData) { - return content.startTime().toString(); + if(content.startTime() == null){ + return "" + } else { + return content.startTime().toString() + } } else if (content is Annotated) { return content.meta().getString("file.timeModified", "") } else { diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/NumassLoaderView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/NumassLoaderView.kt index c80d4b07..9810695e 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/NumassLoaderView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/NumassLoaderView.kt @@ -24,7 +24,6 @@ import javafx.beans.value.ObservableValue import javafx.collections.FXCollections import javafx.event.ActionEvent import javafx.event.EventHandler -import javafx.fxml.FXMLLoader import javafx.geometry.Insets import javafx.geometry.Orientation import javafx.scene.control.* @@ -72,23 +71,6 @@ class NumassLoaderView : View() { private val detectorNormalizeSwitch: CheckBox = CheckBox("Normailize") private val detectorDataExportButton: Button = Button("Export") - init { - val loader = FXMLLoader(javaClass.getResource("/fxml/NumassLoaderView.fxml")) - - loader.setRoot(this) - loader.setController(this) - - try { - loader.load() - } catch (ex: IOException) { - throw RuntimeException(ex) - } - - } - - /** - * Initializes the controller class. - */ init { //setup detector pane plot and sidebar val l = Label("Bin size:") @@ -191,7 +173,7 @@ class NumassLoaderView : View() { getWorkManager().startWork("viewer.numass.hv") { callback: Work -> val t = hvData.get() Platform.runLater { - hvPlot.plot.plottables().clear() + hvPlot.plot.clear() val set = PlottableGroup() for (dp in t) { val block = dp.getString("block", "default") @@ -269,7 +251,7 @@ class NumassLoaderView : View() { */ private fun updateDetectorPane(points: List, binning: Int, normalize: Boolean) { val detectorPlotFrame: FXPlotFrame - if (detectorPlot.plot.config.isEmpty) { + if (detectorPlot.plot == null) { val frameMeta = MetaBuilder("frame") .setValue("title", "Detector response plot") .setNode(MetaBuilder("xAxis") diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/TreeBuilder.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/TreeBuilder.kt deleted file mode 100644 index a29889df..00000000 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/TreeBuilder.kt +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2015 Alexander Nozik. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package inr.numass.viewer - -/** - - * @author darksnake - */ -class TreeBuilder { -// @Throws(StorageException::class) -// fun build(callback: Work, -// numassLoaderDataTree: TreeTableView, -// rootStorage: NumassStorage, -// numassViewBuilder: (NumassData) -> Unit) { -// -// val root = buildNode(rootStorage, numassViewBuilder, callback) -// root.isExpanded = true -// -// Platform.runLater { -// numassLoaderDataTree.root = root -// -// val numassLoaderNameColumn = TreeTableColumn("name") -// -// numassLoaderNameColumn.setCellValueFactory { param: TreeTableColumn.CellDataFeatures -> SimpleStringProperty(param.value.value.name) } -// -// val numassLoaderTimeColumn = TreeTableColumn("time") -// numassLoaderTimeColumn.setCellValueFactory { param: TreeTableColumn.CellDataFeatures -> SimpleStringProperty(param.value.value.time) } -// -// val nummassLoaderDescriptionColumn = TreeTableColumn("description") -// nummassLoaderDescriptionColumn.setCellValueFactory { param: TreeTableColumn.CellDataFeatures -> SimpleStringProperty(param.value.value.description) } -// -// numassLoaderDataTree.columns.setAll(numassLoaderNameColumn, numassLoaderTimeColumn, nummassLoaderDescriptionColumn) -// -// numassLoaderNameColumn.sortType = TreeTableColumn.SortType.ASCENDING -// numassLoaderDataTree.sortOrder.addAll(numassLoaderTimeColumn, numassLoaderNameColumn) -// numassLoaderDataTree.addEventHandler(MouseEvent.MOUSE_CLICKED) { e: MouseEvent -> -// if (e.clickCount == 2) { -// val value = numassLoaderDataTree.focusModel.focusedCell.treeItem.value -// if (value.isLoader) { -// numassViewBuilder(value.loader) -// } -// } -// } -// numassLoaderTimeColumn.isVisible = false -// nummassLoaderDescriptionColumn.setVisible(false) -// } -// -// } -// -// @Throws(StorageException::class) -// private fun buildNode(storage: NumassStorage, numassViewBuilder: (NumassData) -> Unit, callback: Work): TreeItem { -// val node = TreeItem(NumassDataItem(storage)) -// node.children.setAll(buildChildren(storage, numassViewBuilder, callback)) -// return node -// } -// -// private val logger: Logger -// get() = LoggerFactory.getLogger(javaClass) -// -// @Throws(StorageException::class) -// private fun buildChildren(storage: NumassStorage, numassViewBuilder: (NumassData) -> Unit, callback: Work): List> { -// val list = ArrayList>() -// -// storage.shelves().stream().forEach { subStorage -> -// if (subStorage is NumassStorage) { -// try { -// val numassSubStorage = subStorage -// val childNode = buildNode(numassSubStorage, numassViewBuilder, callback) -// if (!childNode.isLeaf) { -// list.add(buildNode(numassSubStorage, numassViewBuilder, callback)) -// } -// } catch (ex: StorageException) { -// logger.error("Error while loading numass storage node", ex) -// } -// -// } -// } -// -// callback.status = "Building storage " + storage.name -// callback.progress = 0.0 -// callback.maxProgress = storage.loaders().size.toDouble() -// storage.loaders().stream() -// .forEach { loader -> -// if (loader is NumassData) { -// callback.status = "Building numass data loader " + loader.getName() -// val numassLoaderTreeItem = TreeItem(NumassDataItem(loader)) -// list.add(numassLoaderTreeItem) -// } -// callback.increaseProgress(1.0) -// } -// -// callback.status = "Loading legacy DAT files" -// callback.progress = 0.0 -// val legacyFiles = storage.legacyFiles() -// callback.maxProgress = legacyFiles.size.toDouble() -// //adding legacy data files -// for (legacyDat in legacyFiles) { -// callback.status = "Loading numass DAT file " + legacyDat.name -// val numassLoaderTreeItem = TreeItem(NumassDataItem(legacyDat)) -// callback.increaseProgress(1.0) -// list.add(numassLoaderTreeItem) -// } -// -// return list -// } -// -} diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/Viewer.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/Viewer.kt index 1d230872..32a6123f 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/Viewer.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/Viewer.kt @@ -2,6 +2,7 @@ package inr.numass.viewer import ch.qos.logback.classic.Level import ch.qos.logback.classic.Logger +import hep.dataforge.context.Global import hep.dataforge.fx.work.WorkManager import hep.dataforge.storage.commons.StorageManager import javafx.stage.Stage @@ -15,6 +16,7 @@ class Viewer : App(MainView::class) { override fun start(stage: Stage) { (LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME) as Logger).level = Level.INFO + Global.setDefaultContext(Global.instance()) StorageManager().startGlobal() WorkManager().startGlobal() super.start(stage) diff --git a/numass-viewer/src/main/resources/fxml/NumassLoaderView.fxml b/numass-viewer/src/main/resources/fxml/NumassLoaderView.fxml index f77e2a5d..1480167f 100644 --- a/numass-viewer/src/main/resources/fxml/NumassLoaderView.fxml +++ b/numass-viewer/src/main/resources/fxml/NumassLoaderView.fxml @@ -20,7 +20,7 @@ limitations under the License. - + @@ -92,4 +92,4 @@ limitations under the License. - +