From 4550c9bf5764735ead01dea73b6c0a5c0a29d910 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 4 Sep 2016 19:40:36 +0300 Subject: [PATCH] Plots refactoring --- numass-main/build.gradle | 12 +++---- .../groovy/inr/numass/LaunchGrindShell.groovy | 12 ++++--- .../main/java/inr/numass/NumassPlugin.java | 26 +++++++++++++- .../workbench/NumassWorkbenchController.java | 34 ++++++++----------- .../java/inr/numass/workbench/Workbench.java | 23 +++++++------ .../java/inr/numass/models/PlotScatter.java | 4 +-- .../models/TestNeLossParametrisation.java | 4 +-- .../models/TransmissionInterpolatorTest.java | 4 +-- .../numass/viewer/MainViewerController.java | 6 ++-- .../inr/numass/viewer/MspViewController.java | 2 +- .../viewer/NumassLoaderViewComponent.java | 6 ++-- 11 files changed, 79 insertions(+), 54 deletions(-) diff --git a/numass-main/build.gradle b/numass-main/build.gradle index fe0c64f9..8dc430f5 100644 --- a/numass-main/build.gradle +++ b/numass-main/build.gradle @@ -8,20 +8,20 @@ mainClassName = mainClass description = """The main head of all numass projects""" dependencies { - compile group: 'commons-cli', name: 'commons-cli', version:'1.+' - compile group: 'commons-io', name: 'commons-io', version:'2.+' + compile group: 'commons-cli', name: 'commons-cli', version: '1.+' + compile group: 'commons-io', name: 'commons-io', version: '2.+' compile project(':dataforge-stat:dataforge-minuit') compile project(':dataforge-fx') - compile project(':dataforge-plots') + compile project(':dataforge-plots:plots-jfc') compile project(':numass-storage') compile project(':dataforge-grind') } -task workbench(dependsOn: classes, type: JavaExec){ +task workbench(dependsOn: classes, type: JavaExec) { main 'inr.numass.workbench.Workbench' classpath = sourceSets.main.runtimeClasspath description "start visual numass workbench" - group "numass" + group "numass" } @@ -30,7 +30,7 @@ task listActions(dependsOn: classes, type: JavaExec) { args "-lc" classpath = sourceSets.main.runtimeClasspath description "print a list of available actions as via -lc command line parameter" - group "numass" + group "numass" } task workspace(dependsOn: classes, type: JavaExec) { diff --git a/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy b/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy index 43a983f7..0f7828da 100644 --- a/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy +++ b/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy @@ -8,7 +8,11 @@ import hep.dataforge.workspace.Workspace * Created by darksnake on 29-Aug-16. */ -GrindShell shell = new GrindShell() -Workspace numass = new GrindLauncher().withSpec(NumassWorkspaceSpec).from(new File("D:\\Work\\Numass\\sterile2016\\workspace.groovy")).buildWorkspace() -shell.bind("numass", numass) -shell.start() +new GrindShell().start { + Workspace numass = new GrindLauncher() + .withSpec(NumassWorkspaceSpec) + .from(new File("D:\\Work\\Numass\\sterile2016\\workspace.groovy")) + .buildWorkspace() + setContext(numass.getContext()) + bind("numass", numass) +} \ No newline at end of file diff --git a/numass-main/src/main/java/inr/numass/NumassPlugin.java b/numass-main/src/main/java/inr/numass/NumassPlugin.java index 2d6f6944..a534f168 100644 --- a/numass-main/src/main/java/inr/numass/NumassPlugin.java +++ b/numass-main/src/main/java/inr/numass/NumassPlugin.java @@ -23,6 +23,9 @@ import hep.dataforge.maths.MathPlugin; import hep.dataforge.meta.Meta; import hep.dataforge.plotfit.PlotFitResultAction; import hep.dataforge.plots.PlotDataAction; +import hep.dataforge.plots.fx.FXPlotUtils; +import hep.dataforge.plots.fx.PlotContainer; +import hep.dataforge.plots.jfreechart.JFreeChartFrame; import hep.dataforge.stat.fit.FitManager; import hep.dataforge.stat.fit.FitPlugin; import hep.dataforge.stat.models.ModelManager; @@ -41,10 +44,31 @@ import org.apache.commons.math3.util.FastMath; * @author Alexander Nozik */ @PluginDef(group = "inr.numass", name = "numass", - dependsOn = {"hep.dataforge:actions", "hep.dataforge:math", "hep.dataforge:MINUIT", "hep.dataforge:plots"}, + dependsOn = {"hep.dataforge:actions", "hep.dataforge:math", "hep.dataforge:MINUIT", "hep.dataforge:plots-jfc"}, description = "Numass data analysis tools") public class NumassPlugin extends BasicPlugin { + /** + * Display a JFreeChart plot frame in a separate stage window + * + * @param title + * @param width + * @param height + * @return + */ + public static JFreeChartFrame displayJFreeChart(String title, double width, double height, Meta meta) { + PlotContainer container = FXPlotUtils.displayContainer(title, width, height); + JFreeChartFrame frame = new JFreeChartFrame(meta); + frame.configureValue("title", title); + container.setPlot(frame); + return frame; + } + + public static JFreeChartFrame displayJFreeChart(String title, Meta meta) { + return displayJFreeChart(title, 800, 600, meta); + } + + @Override public void attach(Context context) { // StorageManager.buildFrom(context); 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 03a750ab..ffcb1110 100644 --- a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java +++ b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java @@ -30,9 +30,22 @@ import hep.dataforge.meta.MetaBuilder; import hep.dataforge.plots.PlotFrame; import hep.dataforge.plots.PlotHolder; import hep.dataforge.plots.PlotsPlugin; +import hep.dataforge.utils.ContextMetaFactory; import hep.dataforge.values.Value; import inr.numass.NumassIO; import inr.numass.NumassProperties; +import javafx.application.Platform; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.value.ObservableValue; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.Node; +import javafx.scene.control.*; +import javafx.stage.FileChooser; +import org.controlsfx.control.StatusBar; + import java.io.File; import java.io.IOException; import java.net.URL; @@ -43,23 +56,6 @@ import java.util.Map; import java.util.ResourceBundle; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; -import javafx.application.Platform; -import javafx.beans.property.BooleanProperty; -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.value.ObservableValue; -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.Node; -import javafx.scene.control.Accordion; -import javafx.scene.control.Alert; -import javafx.scene.control.Tab; -import javafx.scene.control.TabPane; -import javafx.scene.control.TitledPane; -import javafx.scene.control.ToggleButton; -import javafx.stage.FileChooser; -import org.controlsfx.control.StatusBar; -import hep.dataforge.utils.ContextMetaFactory; /** * FXML Controller class @@ -165,7 +161,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder this.context = this.contextFactory.build(parentContext, config); // attachig visual process manager - processWindow.setManager(context.workManager()); + processWindow.setManager(context.taskManager()); // setting io manager context.setIO(new WorkbenchIOManager(new NumassIO(), this)); @@ -340,7 +336,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder runActions(); } } else { - this.context.workManager().shutdown(); + this.context.taskManager().shutdown(); } } diff --git a/numass-main/src/main/java/inr/numass/workbench/Workbench.java b/numass-main/src/main/java/inr/numass/workbench/Workbench.java index 46e6bab9..cadfa997 100644 --- a/numass-main/src/main/java/inr/numass/workbench/Workbench.java +++ b/numass-main/src/main/java/inr/numass/workbench/Workbench.java @@ -7,8 +7,6 @@ package inr.numass.workbench; import hep.dataforge.context.GlobalContext; import inr.numass.Numass; -import java.io.IOException; -import java.text.ParseException; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; @@ -16,12 +14,22 @@ import javafx.scene.Scene; import javafx.stage.Stage; import javafx.stage.WindowEvent; +import java.io.IOException; +import java.text.ParseException; + /** * * @author Alexander Nozik */ public class Workbench extends Application { + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + launch(args); + } + @Override public void start(Stage primaryStage) throws IOException, ParseException { FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/NumassWorkbench.fxml")); @@ -38,9 +46,9 @@ public class Workbench extends Application { scene.getWindow().setOnCloseRequest((WindowEvent event) -> { try { - controller.getContext().workManager().getRoot().cancel(true); + controller.getContext().taskManager().getRoot().cancel(true); } catch (Exception e) { - + } }); } @@ -51,11 +59,4 @@ public class Workbench extends Application { super.stop(); } - /** - * @param args the command line arguments - */ - public static void main(String[] args) { - launch(args); - } - } diff --git a/numass-main/src/test/java/inr/numass/models/PlotScatter.java b/numass-main/src/test/java/inr/numass/models/PlotScatter.java index 69826cad..81e1dafe 100644 --- a/numass-main/src/test/java/inr/numass/models/PlotScatter.java +++ b/numass-main/src/test/java/inr/numass/models/PlotScatter.java @@ -16,7 +16,7 @@ package inr.numass.models; import hep.dataforge.stat.fit.ParamSet; -import hep.dataforge.plots.fx.FXPlotUtils; +import inr.numass.NumassPlugin; /** * @@ -36,6 +36,6 @@ public class PlotScatter { + "'ionW' = 11.33 ± 0.43\n" + "'exIonRatio' = 4.83 ± 0.36" ); - LossCalculator.plotScatter(FXPlotUtils.displayJFreeChart("Loss function", null),pars); + LossCalculator.plotScatter(NumassPlugin.displayJFreeChart("Loss function", null), pars); } } diff --git a/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java b/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java index 1547fc6e..ff21705f 100644 --- a/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java +++ b/numass-main/src/test/java/inr/numass/models/TestNeLossParametrisation.java @@ -18,7 +18,7 @@ package inr.numass.models; import hep.dataforge.maths.integration.GaussRuleIntegrator; import hep.dataforge.plots.PlotFrame; import hep.dataforge.plots.data.PlottableXYFunction; -import hep.dataforge.plots.fx.FXPlotUtils; +import inr.numass.NumassPlugin; import org.apache.commons.math3.analysis.UnivariateFunction; /** @@ -31,7 +31,7 @@ public class TestNeLossParametrisation { * @param args the command line arguments */ public static void main(String[] args) { - PlotFrame frame = FXPlotUtils.displayJFreeChart("Loss parametrisation test", null); + PlotFrame frame = NumassPlugin.displayJFreeChart("Loss parametrisation test", null); //JFreeChartFrame.drawFrame("Loss parametrisation test", null); UnivariateFunction oldFunction = LossCalculator.getSingleScatterFunction(); UnivariateFunction newFunction = getSingleScatterFunction(12.86, 16.78, 1.65, 12.38, 4.79); diff --git a/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java b/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java index 57335066..9df1899a 100644 --- a/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java +++ b/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java @@ -18,8 +18,8 @@ package inr.numass.models; import hep.dataforge.context.GlobalContext; import hep.dataforge.plots.data.PlottableData; import hep.dataforge.plots.data.PlottableXYFunction; -import hep.dataforge.plots.fx.FXPlotUtils; import hep.dataforge.plots.jfreechart.JFreeChartFrame; +import inr.numass.NumassPlugin; /** * @@ -28,7 +28,7 @@ import hep.dataforge.plots.jfreechart.JFreeChartFrame; public class TransmissionInterpolatorTest { public static void main(String[] args) { - JFreeChartFrame frame = FXPlotUtils.displayJFreeChart("TransmissionInterpolatorTest", null); + JFreeChartFrame frame = NumassPlugin.displayJFreeChart("TransmissionInterpolatorTest", null); //JFreeChartFrame.drawFrame("TransmissionInterpolatorTest", null); TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(GlobalContext.instance(), "d:\\sterile-new\\loss2014-11\\.dataforge\\merge\\empty_sum.onComplete", "Uset", "CR", 15, 0.8, 19002d); 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 5b0d2c10..4a10bb8c 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java @@ -129,7 +129,7 @@ public class MainViewerController implements Initializable { } private void loadDirectory(String path) { - getContext().workManager().submit("viewer.loadDirectory", (ProgressCallback callback) -> { + getContext().taskManager().submit("viewer.loadDirectory", (ProgressCallback callback) -> { callback.updateTitle("Load storage (" + path + ")"); callback.setProgress(-1); callback.updateMessage("Building numass storage tree..."); @@ -151,8 +151,8 @@ public class MainViewerController implements Initializable { public void setRootStorage(NumassStorage root) { - getContext().workManager().cleanup(); - getContext().workManager().submit("viewer.storage.load", (ProgressCallback callback) -> { + getContext().taskManager().cleanup(); + getContext().taskManager().submit("viewer.storage.load", (ProgressCallback callback) -> { callback.updateTitle("Fill data to UI (" + root.getName() + ")"); callback.setProgress(-1); Platform.runLater(() -> statusBar.setProgress(-1)); diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java index 47a6d242..5cddebe9 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java @@ -87,7 +87,7 @@ public class MspViewController { public void fillMspData(Storage rootStorage) { if (rootStorage != null) { - context.workManager().submit("viewer.msp.fill", (ProgressCallback callback) -> { + context.taskManager().submit("viewer.msp.fill", (ProgressCallback callback) -> { try { // callback.updateTitle("Fill msp data (" + rootStorage.getName() + ")"); 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 0890879b..2dc6e421 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java @@ -214,7 +214,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab public void loadData(NumassData data) { this.data = data; if (data != null) { - context.workManager().>submit("viewer.numass.load", (ProgressCallback callback) -> { + context.taskManager().>submit("viewer.numass.load", (ProgressCallback callback) -> { callback.updateTitle("Load numass data (" + data.getName() + ")"); points = data.getNMPoints(); @@ -239,7 +239,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab } private void setupHVPane(Supplier hvData) { - context.workManager().submit("viewer.numass.hv", (ProgressCallback callback) -> { + context.taskManager().submit("viewer.numass.hv", (ProgressCallback callback) -> { Table t = hvData.get(); Platform.runLater(() -> { if (t != null) { @@ -343,7 +343,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab detectorPlot.removePlot(); } - context.workManager().submit("viewer.numass.load.detector", (ProgressCallback callback) -> { + context.taskManager().submit("viewer.numass.load.detector", (ProgressCallback callback) -> { Meta plottableConfig = new MetaBuilder("plot") .setValue("connectionType", "step") .setValue("thickness", 2)