From d65c29cde89ad5e813b97f6bf5c2cadbbe200cd9 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 18 May 2016 13:12:59 +0300 Subject: [PATCH] minor improvements. Checker framework added as global dependency --- .../main/java/inr/numass/NumassContext.java | 1 - .../java/inr/numass/NumassProperties.java | 54 +++++++++++++++++++ .../workbench/NumassWorkbenchController.java | 9 +++- numass-viewer/build.gradle | 2 +- .../numass/viewer/MainViewerController.java | 10 +++- .../viewer/NumassLoaderViewComponent.java | 26 +-------- 6 files changed, 73 insertions(+), 29 deletions(-) create mode 100644 numass-main/src/main/java/inr/numass/NumassProperties.java diff --git a/numass-main/src/main/java/inr/numass/NumassContext.java b/numass-main/src/main/java/inr/numass/NumassContext.java index 2a4cf75a..f0e71595 100644 --- a/numass-main/src/main/java/inr/numass/NumassContext.java +++ b/numass-main/src/main/java/inr/numass/NumassContext.java @@ -36,7 +36,6 @@ public class NumassContext extends Context { public static UnivariateIntegrator defaultIntegrator = new GaussRuleIntegrator(300); public static UnivariateIntegrator highDensityIntegrator = new GaussRuleIntegrator(500); - public NumassContext(Context parent, Meta config) { super(parent, "numass", config); init(); diff --git a/numass-main/src/main/java/inr/numass/NumassProperties.java b/numass-main/src/main/java/inr/numass/NumassProperties.java new file mode 100644 index 00000000..cbcf5aaf --- /dev/null +++ b/numass-main/src/main/java/inr/numass/NumassProperties.java @@ -0,0 +1,54 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package inr.numass; + +import hep.dataforge.context.GlobalContext; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +/** + * + * @author Alexander Nozik + */ +public class NumassProperties { + + private static File getNumassPropertiesFile() throws IOException { + File file = new File(GlobalContext.instance().getUserDirectory(), "numass"); + if (!file.exists()) { + file.mkdirs(); + } + file = new File(file, "numass.cfg"); + if(!file.exists()){ + file.createNewFile(); + } + return file; + } + + public static String getNumassProperty(String key) { + try { + Properties props = new Properties(); + props.load(new FileInputStream(getNumassPropertiesFile())); + return props.getProperty(key); + } catch (IOException ex) { + return null; + } + } + + public synchronized static void setNumassProperty(String key, String value) { + try { + Properties props = new Properties(); + File store = getNumassPropertiesFile(); + props.load(new FileInputStream(store)); + props.setProperty(key, value); + props.store(new FileOutputStream(store), ""); + } catch (IOException ex) { + GlobalContext.instance().getLogger().error("Failed to save numass properties", ex); + } + } +} diff --git a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java index 41f40697..3ebdb1c1 100644 --- a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java +++ b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java @@ -20,7 +20,6 @@ import hep.dataforge.fx.ConsoleFragment; import hep.dataforge.fx.FXProcessManager; import hep.dataforge.fx.LogOutputPane; import hep.dataforge.fx.MetaEditor; -import hep.dataforge.fx.MetaTreeItem; import hep.dataforge.fx.ProcessManagerFragment; import hep.dataforge.io.IOManager; import hep.dataforge.io.MetaFileReader; @@ -34,6 +33,7 @@ import hep.dataforge.plots.PlotsPlugin; import hep.dataforge.utils.MetaFactory; import hep.dataforge.values.Value; import inr.numass.NumassIO; +import inr.numass.NumassProperties; import java.io.File; import java.io.IOException; import java.net.URL; @@ -275,8 +275,15 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder statusBar.setText("Loading configuration file..."); FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open Configuration File"); + String storageRoot = NumassProperties.getNumassProperty("numass.workbench.root"); + if (storageRoot == null) { + fileChooser.setInitialDirectory(new File(".").getAbsoluteFile()); + } else { + fileChooser.setInitialDirectory(new File(storageRoot)); + } File cfgFile = fileChooser.showOpenDialog(((Node) event.getTarget()).getScene().getWindow()); if (cfgFile != null) { + NumassProperties.setNumassProperty("numass.workbench.root", cfgFile.getParentFile().getAbsolutePath()); try { Meta cfg = MetaFileReader.read(cfgFile).build(); this.loadConfig(cfg); diff --git a/numass-viewer/build.gradle b/numass-viewer/build.gradle index 467d0e6b..c807b38d 100644 --- a/numass-viewer/build.gradle +++ b/numass-viewer/build.gradle @@ -5,7 +5,7 @@ if (!hasProperty('mainClass')) { } mainClassName = mainClass -version = "0.3.1" +version = "0.3.2" description = "The viewer for numass data" diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java index 91ddb04e..a2e33b2f 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java @@ -21,6 +21,8 @@ import hep.dataforge.context.ProcessManager; import hep.dataforge.exceptions.StorageException; import hep.dataforge.fx.ConsoleFragment; import hep.dataforge.fx.ProcessManagerFragment; +import inr.numass.NumassContext; +import inr.numass.NumassProperties; import inr.numass.storage.NumassData; import inr.numass.storage.NumassStorage; import java.io.File; @@ -122,11 +124,17 @@ public class MainViewerController implements Initializable { DirectoryChooser chooser = new DirectoryChooser(); chooser.setTitle("Select numass storage root"); - chooser.setInitialDirectory(new File(".").getAbsoluteFile()); + String storageRoot = NumassProperties.getNumassProperty("numass.storage.root"); + if (storageRoot == null) { + chooser.setInitialDirectory(new File(".").getAbsoluteFile()); + } else { + chooser.setInitialDirectory(new File(storageRoot)); + } final File rootDir = chooser.showDialog(((Node) event.getTarget()).getScene().getWindow()); if (rootDir != null) { + NumassProperties.setNumassProperty("numass.storage.root", rootDir.getAbsolutePath()); loadDirectory(rootDir.toURI().toString()); } } diff --git a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java index 2069e205..ee2d88c7 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java @@ -164,7 +164,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab detectorDataExportButton.setMaxWidth(Double.MAX_VALUE); detectorDataExportButton.setOnAction(this::onExportButtonClick); detectorPlot.addToSideBar(detectorDataExportButton); - + detectorPlot.setSideBarPosition(0.7); //setup spectrum pane @@ -374,30 +374,6 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab return plottables; } - @FXML - private void checkAllAction(ActionEvent event) { - detectorPointListView.getCheckModel().checkAll(); - } - - @FXML - private void uncheckAllAction(ActionEvent event) { - detectorPointListView.getCheckModel().clearChecks(); - } - - @FXML - private void checkSelectedAction(ActionEvent event) { - for (Integer i : detectorPointListView.getSelectionModel().getSelectedIndices()) { - detectorPointListView.getCheckModel().check(i); - } - } - - @FXML - private void uncheckSelectedAction(ActionEvent event) { - for (Integer i : detectorPointListView.getSelectionModel().getSelectedIndices()) { - detectorPointListView.getCheckModel().clearCheck(i); - } - } - @FXML private void onSpectrumExportClick(ActionEvent event) { if (points != null && !points.isEmpty()) {