From 9a9a0beca4b192a97690be4336bf17c498ebfed8 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 14 Apr 2016 20:45:11 +0300 Subject: [PATCH] [no commit message] --- numass-control/msp/build.gradle | 6 +- .../msp/private/cache/retriever/catalog.xml | 4 + .../java/javase/overview/index.html | 1086 +++++++++++++++++ .../inr/numass/control/msp/MspDevice.java | 107 +- .../inr/numass/control/msp/fx/MspApp.java | 35 +- .../control/msp/fx/MspViewController.java | 175 ++- .../msp/src/main/resources/fxml/MspView.fxml | 106 +- .../java/inr/numass/readvac/app/ReadVac.java | 2 +- .../readvac/fx/VacCollectorController.java | 77 +- .../src/main/resources/fxml/VacCollector.fxml | 10 +- 10 files changed, 1359 insertions(+), 249 deletions(-) create mode 100644 numass-control/msp/private/cache/retriever/catalog.xml create mode 100644 numass-control/msp/private/cache/retriever/www.oracle.com/technetwork/java/javase/overview/index.html diff --git a/numass-control/msp/build.gradle b/numass-control/msp/build.gradle index 84982ef5..54bee40a 100644 --- a/numass-control/msp/build.gradle +++ b/numass-control/msp/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'application' -version = "0.2.4" +version = "0.3.0" if (!hasProperty('mainClass')) { ext.mainClass = 'inr.numass.control.msp.fx.MspApp' @@ -9,9 +9,7 @@ mainClassName = mainClass dependencies { - compile 'ch.qos.logback:logback-classic:1.1.0+' - compile 'org.scream3r:jssc:2.8.0' + compile project(':numass-storage:numass-client') compile project(':dataforge-plots') - compile project(':dataforge-storage') compile project(':dataforge-control') } \ No newline at end of file diff --git a/numass-control/msp/private/cache/retriever/catalog.xml b/numass-control/msp/private/cache/retriever/catalog.xml new file mode 100644 index 00000000..a63b4498 --- /dev/null +++ b/numass-control/msp/private/cache/retriever/catalog.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/numass-control/msp/private/cache/retriever/www.oracle.com/technetwork/java/javase/overview/index.html b/numass-control/msp/private/cache/retriever/www.oracle.com/technetwork/java/javase/overview/index.html new file mode 100644 index 00000000..9c009fdd --- /dev/null +++ b/numass-control/msp/private/cache/retriever/www.oracle.com/technetwork/java/javase/overview/index.html @@ -0,0 +1,1086 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Java SE | Oracle Technology Network | Oracle + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + +
+
+ + + + + + +
+ +
+
+ + + + + + + + + + + + + +
+
+
+ + + + + + + + + + +
+
+ +

Java SE at a Glance

 
 

Java Platform, Standard Edition (Java SE) lets you develop and deploy Java applications on desktops and servers, as well as in today's demanding embedded environments. Java offers the rich user interface, performance, versatility, portability, and security that today's applicationsrequire.


Auto-update Notice & End of Public Updates for Oracle JDK 7

Coincident with the January 2015 CPU release users with the auto-update feature enabled were migrated from Oracle JRE 7 to Oracle JRE 8. Also, please note the April 2015 CPU release was the last Oracle JDK 7 publicly available update. For more information, and details on how to receive longer term support for Oracle JDK 7, please see the Oracle Java SE Support Roadmap.
 

 

What's New

Advanced Management Console 2.2
Provides system administrators an effective control over diverse Java versions running on desktops in the enterprise enabling a more secure environment and enhanced application experience and availability. Documentation

Java Platform, Standard Edition 8 Update 77 (Java SE 8u77) is Now Available
This latest release of the Java Platform includes important security fixes. Oracle strongly recommends that all Java SE 8 users upgrade to this release.
JDK for ARM releases are available on the same page as the downloads for other platforms

arrow Download  arrow  Release Notes

Java SE 8 is Now Available
The Java Platform, Standard Edition 8 (Java SE 8) is a major feature release. It contains new features and enhancements in many functional areas. Java SE 8 delivers enhanced developer productivity and significant application performance increases through reduced boilerplate code, improved collections and annotations, simpler parallel programming models and more efficient use of modern, multi-core processors. See what's new in JDK 8 for more details.
arrow Download  arrow  Release Notes

Security of the Java Platform
A description of security information provided by role. For developers, system administrators, home users, and security professionals.

Java RIA Security Checklist
Recently announced changes scheduled for Java 7 update 51 (January 2014) have established that the default security slider will require code signatures and the Permissions Manifest attribute. This checklist is intended to provide best practices to help development teams track work necessary to accommodate user prompts.

LiveConnect changes in 7u45 
Java 7 update 45 (October 2013) introduces a new warning to users of LiveConnect applications. LiveConnect is a technology for Rich Internet Applications that allows JavaScript on a web page to make calls into an RIA, allowing the two to work together and load content. RIAs that do not use LiveConnect are unaffected by this change. Read More

Oracle Releases New Diagnostic, Monitoring, Security and Deployment Capabilities for Java SE 7 (Press Release)  Video

Java Mission Control 
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis.
Release Notes   Demo   White Paper

Deployment Rule Set 
Deployment rule set allows a desktop administrator to control the level of Java client compatibility and default prompts across an organization. Documentation 

Java API Documentation Updater Tool 

Java Usage Tracking and Visualization with Oracle Fusion Middleware 

Server JRE 
Starting with Java SE 7u21, a Server Java Runtime Environment (Server JRE) package is available for deploying Java applications on servers. Learn More

Java Applet & Web Start - Code Signing 
Starting with Java SE 7u21 all Java Applets and Web Start Applications are encouraged to be signed with a trusted certificate. Learn More

Archive of Technical Articles

 

Updates

Java SE 8u77 Released
Java SE 8u77 is the latest Security Alert releases for JDK 8.

arrow Release Notes  arrow  Download


communityProducts and Training
 

Oracle Java SE Advanced & Suite 
Expert monitoring, diagnostics, and centralized management for enterprise and ISV Java-based applications.
?
Oracle Java SE Support

Access Oracle Premier Support for the components and features included with Java SE.

Training & Certification:

?
Learn More about Java Software

Java can reduce costs, drive innovation, and improve application services.



community Community

JavaOne
JavaOne 2015 has concluded, but the Learning Lives On

Did you miss a JavaOne keynote or session? You can find those here. And 'Save the Date' for Oracle OpenWorld 2016 September 18-22, 2016!

Java 8 Event Kit
Access the "Create the Future with Java 8 Event Kit" - run your own Java 8 event using the resources designed for Java User Groups (JUGs). The kit includes a fully scripted technical presentation, intro video, promotional tools and more. Learn More

Adopt a JSR Program
This program is intended to encourage JUG members to get involved in a Java Specification Request (JSR) and to evangelise that JSR to their JUG and the wider Java community in order to increase grass roots participation. Learn More

Java.net 
- The Source for Java Technology Collaboration

Java Embedded Community

JavaFX Community

NightHacking LogoNighthacking.com
The NightHacking Java 8 Tour is the inaugural leg of the Java 8 Tour event where the evangelism team will be crossing the globe to speak at conferences and Java User Groups to spread the word about the new Java 8 release.


 


Participate
 

Make the Future Java Outreach Program
Together, we can inspire future technologists to learn more about Java and the opportunities it brings. The Make the Future Java program offers resources, tool kits and promotional items you can use for Java outreach within your local community.

Join a Java User Group (JUG)
Java User Groups (JUGs) are volunteer organizations that strive to distribute Java-related knowledge around the world. They provide a meeting place for Java users to get information, share resources and solutions, increase networking, expand Java Technology expertise, and above all, drink beer, eat pizza and have fun. Find a JUG and become a part of the Java community today!

Java ForumsI Code Java
Read about and share ideas and suggestions about Java technology on the discussion forums. Start with the New to Java or the more advanced Java Programming category.

Gimme Java - Show your true colors!
These Java designs are yours to take and use. Post on your Website, put them on t-shirts or coffee mugs—use them just about anywhere except on a Java product—and let the world know about your passion for Java.

 

 

Java SE Site Map

+ +
+
+
+
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + +
Left Curve +
Java SDKs and Tools
+
Right Curve
+ +
+ + + +
Left Curve
Java Resources
Right Curve
+ + +
+
+ + +
+ + +
+ + + + + + + + + + + + +
+ + + + + + + + + + + + + diff --git a/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java b/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java index 603ef823..11b85ec3 100644 --- a/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java +++ b/numass-control/msp/src/main/java/inr/numass/control/msp/MspDevice.java @@ -23,8 +23,6 @@ import hep.dataforge.control.measurements.AbstractMeasurement; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.ports.PortHandler; import hep.dataforge.control.ports.TcpPortHandler; -import hep.dataforge.points.Format; -import hep.dataforge.points.FormatBuilder; import hep.dataforge.points.DataPoint; import hep.dataforge.points.MapPoint; import hep.dataforge.exceptions.ControlException; @@ -32,12 +30,15 @@ import hep.dataforge.exceptions.MeasurementException; import hep.dataforge.exceptions.PortException; import hep.dataforge.exceptions.StorageException; import hep.dataforge.meta.Meta; +import hep.dataforge.points.Format; +import hep.dataforge.points.FormatBuilder; import hep.dataforge.storage.api.PointLoader; import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.values.Value; import java.time.Instant; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -49,7 +50,7 @@ import java.util.function.Consumer; * * @author Alexander Nozik */ -@RoleDef(name = Roles.STORAGE_ROLE) +@RoleDef(name = Roles.STORAGE_ROLE, objectType = StorageConnection.class) public class MspDevice extends SingleMeasurementDevice implements PortHandler.PortController { // private static final String PEAK_SET_PATH = "peakJump.peak"; @@ -63,6 +64,10 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po private Consumer responseDelegate; private Consumer errorDelegate; + boolean connected = false; + boolean selected = false; + boolean controlled = false; + // public MspDevice(String name, Context context, Meta config) { // super(name, context, config); // } @@ -159,7 +164,8 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po response = sendAndWait("Select", sensorName); if (response.isOK()) { - updateState("selected", true); + selected = true; +// updateState("selected", true); } else { error(response.errorDescription(), null); return false; @@ -167,12 +173,15 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po response = sendAndWait("Control", "inr.numass.msp", "1.0"); if (response.isOK()) { - updateState("controlled", true); + controlled = true; +// invalidateState("controlled"); +// updateState("controlled", true); } else { error(response.errorDescription(), null); return false; } - updateState("connected", true); + connected = true; +// updateState("connected", true); return true; } else { return !sendAndWait("Release").isOK(); @@ -243,21 +252,28 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po } public boolean isConnected() { - return getState("connected") != null && getState("connected").booleanValue(); + return connected; + //return getState("connected") != null && getState("connected").booleanValue(); } public boolean isSelected() { - return getState("selected") != null && getState("selected").booleanValue(); + return selected; + //return getState("selected") != null && getState("selected").booleanValue(); } public boolean isControlled() { - return getState("controlled") != null && getState("controlled").booleanValue(); + return controlled; + //return getState("controlled") != null && getState("controlled").booleanValue(); } public boolean isFilamentOn() { return getState("filamentOn").booleanValue(); } + public void selectFillament(int fillament) throws PortException { + sendAndWait("FilamentSelect", fillament); + } + /** * Turn filament on or off * @@ -372,41 +388,39 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po private final Map measurement = new ConcurrentSkipListMap<>(); private Map peakMap; - private List loaders = new ArrayList<>(); + private final Map loaderMap = new HashMap<>(); +// private List loaders = new ArrayList<>(); private final Meta meta; + private double zero = 0; public PeakJumpMeasurement(Meta meta) { this.meta = meta; } - private void prepareLoaders() { - loaders = new ArrayList<>(); - forEachTypedConnection(Roles.STORAGE_ROLE, StorageConnection.class, (StorageConnection con) -> { - try { - Storage storage = con.getStorage(); + private PointLoader makeLoader(StorageConnection connection) { - if (peakMap == null) { - throw new IllegalStateException("Peak map is not initialized"); - } + try { + Storage storage = connection.getStorage(); - FormatBuilder builder = new FormatBuilder().addTime("timestamp"); - for (String peakName : this.peakMap.values()) { - builder.addNumber(peakName); - } - - Format format = builder.build(); - - //TODO Переделать!!! - String run = meta().getString("storage.run", ""); - - String suffix = Integer.toString((int) Instant.now().toEpochMilli()); - PointLoader loader = LoaderFactory - .buildPointLoder(storage, "msp" + suffix, run, "timestamp", format); - loaders.add(loader); - } catch (StorageException ex) { - getLogger().error("Failed to initialize peak jump loader", ex); + if (peakMap == null) { + throw new IllegalStateException("Peak map is not initialized"); } - }); + + FormatBuilder builder = new FormatBuilder().addTime("timestamp"); + this.peakMap.values().stream().forEach((peakName) -> { + builder.addNumber(peakName); + }); + + Format format = builder.build(); + + String suffix = Integer.toString((int) Instant.now().toEpochMilli()); + PointLoader loader = LoaderFactory + .buildPointLoder(storage, "msp" + suffix, "", "timestamp", format); + return loader; + } catch (StorageException ex) { + getLogger().error("Failed to create Loader", ex); + return null; + } } @Override @@ -427,7 +441,6 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po throw new ControlException("Can't add mass to measurement measurement for msp"); } } - prepareLoaders(); } else { throw new ControlException("Can't create measurement for msp"); } @@ -454,6 +467,13 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po boolean stop = sendAndWait("ScanStop").isOK(); afterStop(); responseDelegate = null; + loaderMap.values().forEach(loader -> { + try { + loader.close(); + } catch (Exception ex) { + getLogger().error("Failed to close Loader", ex); + } + }); return stop; } catch (PortException ex) { throw new MeasurementException(ex); @@ -468,9 +488,11 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po switch (response.getCommandName()) { case "MassReading": double mass = Double.parseDouble(response.get(0, 1)); - double value = Double.parseDouble(response.get(0, 2)); + double value = Double.parseDouble(response.get(0, 2)) / 100d; measurement.put((int) Math.floor(mass + 0.5), value); break; + case "ZeroReading": + zero = Double.parseDouble(response.get(0, 2)) / 100d; case "StartingScan": if (mspListener != null && !measurement.isEmpty()) { if (peakMap == null) { @@ -490,13 +512,14 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po if (isFilamentOn()) { mspListener.acceptScan(measurement); - for (PointLoader loader : this.loaders) { + forEachTypedConnection(Roles.STORAGE_ROLE, StorageConnection.class, (StorageConnection connection) -> { + PointLoader pl = loaderMap.computeIfAbsent(connection, con -> makeLoader(con)); try { - loader.push(point); + pl.push(point); } catch (StorageException ex) { - getLogger().error("Push to repo failed", ex); + getLogger().error("Push to loader failed", ex); } - } + }); } measurement.clear(); @@ -505,7 +528,7 @@ public class MspDevice extends SingleMeasurementDevice implements PortHandler.Po if (numScans == 0) { try { - send("ScanResume", 2); + send("ScanResume", 10); //FIXME обработать ошибку связи } catch (PortException ex) { error(null, ex); diff --git a/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspApp.java b/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspApp.java index a4f8befc..8e693028 100644 --- a/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspApp.java +++ b/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspApp.java @@ -17,9 +17,11 @@ package inr.numass.control.msp.fx; import ch.qos.logback.classic.Level; import hep.dataforge.context.GlobalContext; +import hep.dataforge.io.MetaFileReader; +import hep.dataforge.io.XMLMetaReader; +import hep.dataforge.meta.Meta; import hep.dataforge.storage.commons.StorageManager; import java.io.File; -import java.io.IOException; import java.util.Locale; import javafx.application.Application; import javafx.fxml.FXMLLoader; @@ -37,26 +39,31 @@ public class MspApp extends Application { MspViewController controller; @Override - public void start(Stage primaryStage) throws IOException { + public void start(Stage primaryStage) throws Exception { Locale.setDefault(Locale.US);// чтобы отделение десятичных знаков было точкой ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); rootLogger.setLevel(Level.INFO); new StorageManager().startGlobal(); + String configFileName = getParameters().getNamed().get("config"); + if (configFileName == null) { + configFileName = "msp-config.xml"; + } + File configFile = new File(configFileName); + Meta config; + if (configFile.exists()) { + config = MetaFileReader.read(configFile).build(); + } else { +// throw new RuntimeException("Configuration file not found"); + config = new XMLMetaReader().read(MspApp.class.getClassLoader().getResourceAsStream("config/msp-config.xml"), -1, null); + } + FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/MspView.fxml")); Parent parent = loader.load(); controller = loader.getController(); - try { - String configPath = getParameters().getNamed().get("config"); - if (configPath != null) { - File configFile = new File(configPath); - controller.setDeviceConfig(GlobalContext.instance(), configFile); - } - } catch (Exception ex) { - LoggerFactory.getLogger(getClass()).error("Failed to load predefined configuration", ex); - } + controller.setDeviceConfig(GlobalContext.instance(), config); Scene scene = new Scene(parent, 600, 400); @@ -72,9 +79,9 @@ public class MspApp extends Application { @Override public void stop() throws Exception { - super.stop(); //To change body of generated methods, choose Tools | Templates. - controller.disconnect(); - System.exit(0); + super.stop(); + controller.shutdown(); +// System.exit(0); } /** diff --git a/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java b/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java index 07d9e6b9..939c0940 100644 --- a/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java +++ b/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java @@ -22,6 +22,8 @@ import hep.dataforge.control.connections.StorageConnection; import hep.dataforge.points.MapPoint; import hep.dataforge.exceptions.ControlException; import hep.dataforge.exceptions.PortException; +import hep.dataforge.exceptions.StorageException; +import hep.dataforge.fx.ConsoleWindow; import hep.dataforge.io.MetaFileReader; import hep.dataforge.meta.ConfigChangeListener; import hep.dataforge.meta.Configuration; @@ -29,9 +31,10 @@ import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; import hep.dataforge.plots.data.DynamicPlottable; import hep.dataforge.plots.data.DynamicPlottableSet; +import hep.dataforge.plots.fx.PlotContainer; import hep.dataforge.plots.jfreechart.JFreeChartFrame; +import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.commons.StorageManager; -import hep.dataforge.storage.filestorage.FileStorage; import hep.dataforge.values.Value; import inr.numass.control.msp.MspDevice; import inr.numass.control.msp.MspListener; @@ -44,11 +47,12 @@ import java.util.List; import java.util.Map; import java.util.ResourceBundle; import javafx.application.Platform; +import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Alert; -import javafx.scene.control.Button; +import javafx.scene.control.ComboBox; import javafx.scene.control.Slider; import javafx.scene.control.TextArea; import javafx.scene.control.ToggleButton; @@ -56,8 +60,12 @@ import javafx.scene.input.DragEvent; import javafx.scene.layout.AnchorPane; import javafx.scene.paint.Paint; import javafx.scene.shape.Circle; -import javafx.stage.FileChooser; +import javafx.stage.DirectoryChooser; +import javafx.util.StringConverter; +import org.controlsfx.control.ToggleSwitch; import org.slf4j.LoggerFactory; +import inr.numass.client.NumassClient; +import javafx.beans.value.ObservableValue; /** * FXML Controller class @@ -74,26 +82,13 @@ public class MspViewController implements Initializable, MspListener { private Configuration viewConfig; - private JFreeChartFrame plotFrame; + private JFreeChartFrame plot; private final DynamicPlottableSet plottables = new DynamicPlottableSet(); private final String mspName = "msp"; - @FXML - private Slider autoRangeSlider; - @FXML - private ToggleButton fillamentButton; - @FXML - private Circle fillamentIndicator; - @FXML private TextArea logArea; - @FXML - private ToggleButton plotButton; - @FXML - private AnchorPane plotPane; - @FXML - private Button loadConfigButton; private final ConfigChangeListener viewConfigObserver = new ConfigChangeListener() { @@ -109,7 +104,57 @@ public class MspViewController implements Initializable, MspListener { }; - public MspViewController() { + private StorageConnection connection; + + @FXML + private Slider autoRangeSlider; + @FXML + private ToggleSwitch fillamentButton; + @FXML + private Circle fillamentIndicator; + @FXML + private ToggleButton plotButton; + @FXML + private AnchorPane plotPane; + @FXML + private ToggleButton consoleButton; + @FXML + private ComboBox fillamentSelector; + @FXML + private ToggleButton storeButton; + + /** + * Initializes the controller class. + * + * @param url + * @param rb + */ + @Override + public void initialize(URL url, ResourceBundle rb) { + ConsoleWindow cw = new ConsoleWindow(consoleButton); + this.logArea = cw.getTextArea(); + fillamentSelector.setItems(FXCollections.observableArrayList(1, 2)); + fillamentSelector.setConverter(new StringConverter() { + @Override + public String toString(Integer object) { + return "Fillament " + object; + } + + @Override + public Integer fromString(String string) { + return Integer.parseInt(string.substring(9)); + } + }); + + fillamentSelector.getSelectionModel().select(0); + fillamentButton.selectedProperty().addListener((ObservableValue observable, Boolean oldValue, Boolean newValue) -> { + try { + fillamentSelector.setDisable(newValue); + getDevice().setFileamentOn(newValue); + } catch (PortException ex) { + device.getLogger().error("Failed to toggle fillaments"); + } + }); } public Configuration getViewConfig() { @@ -159,9 +204,7 @@ public class MspViewController implements Initializable, MspListener { device.setName(mspName); device.setContext(context); device.setMeta(mspConfig); - if (mspConfig.hasNode("storage")) { - device.connect(new StorageConnection(StorageManager.buildFrom(context).buildStorage(mspConfig.getNode("storage"))), Roles.STORAGE_ROLE); - } + try { getDevice().setListener(this); getDevice().init(); @@ -201,19 +244,22 @@ public class MspViewController implements Initializable, MspListener { .setValue("axisUnits", "mbar") ) .setValue("xAxis.type", "time"); - this.plotFrame = new JFreeChartFrame(mspName, plotConfig).display(plotPane); + + this.plot = new JFreeChartFrame(mspName, plotConfig); + PlotContainer container = PlotContainer.anchorTo(plotPane); + container.setPlot(plot); updatePlot(); // this.plot = DynamicPlot.attachToFX(plotPane, new AnnotationBuilder("plot-config").putValue("logY", true).build()); // plot.setAutoRange(30 * 60); } public void updatePlot() { - if (plotFrame == null) { + if (plot == null) { initPlot(); } Meta config = getViewConfig(); if (config.hasNode("plotFrame")) { - this.plotFrame.configure(config.getNode("plotFrame")); + this.plot.configure(config.getNode("plotFrame")); } if (config.hasNode("peakJump.line")) { for (Meta an : config.getNodes("peakJump.line")) { @@ -223,7 +269,7 @@ public class MspViewController implements Initializable, MspListener { DynamicPlottable newPlottable = new DynamicPlottable(mass, mass); newPlottable.configure(an); this.plottables.addPlottable(newPlottable); - plotFrame.add(newPlottable); + plot.add(newPlottable); } else { plottables.getPlottable(mass).configure(an); } @@ -270,40 +316,11 @@ public class MspViewController implements Initializable, MspListener { } - /** - * Initializes the controller class. - * - * @param url - * @param rb - */ - @Override - public void initialize(URL url, ResourceBundle rb) { - } - @FXML private void onAutoRangeChange(DragEvent event) { plottables.setMaxAge((int) (this.autoRangeSlider.getValue() * 60 * 1000)); } - @FXML - private void onFillamentToggle(ActionEvent event) throws PortException { - getDevice().setFileamentOn(fillamentButton.isSelected()); - } - - @FXML - private void onLoadConfig(ActionEvent event) { - FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle("Open Resource File"); - fileChooser.setInitialFileName(DEFAULT_CONFIG_LOCATION); - fileChooser.setInitialDirectory(GlobalContext.instance().io().getRootDirectory()); - fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("xml", "*.xml", "*.XML")); - fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("all", "*.*")); - File cfgFile = fileChooser.showOpenDialog(loadConfigButton.getScene().getWindow()); - if (cfgFile != null) { - setDeviceConfig(GlobalContext.instance(), cfgFile); - } - } - @FXML private void onPlotToggle(ActionEvent event) throws ControlException { if (plotButton.isSelected()) { @@ -326,7 +343,7 @@ public class MspViewController implements Initializable, MspListener { } - public void disconnect() throws IOException, PortException, ControlException { + public void shutdown() throws IOException, PortException, ControlException { getDevice().shutdown(); } @@ -349,4 +366,52 @@ public class MspViewController implements Initializable, MspListener { }); } + @FXML + private void onStoreButtonClick(ActionEvent event) { + if (storeButton.isSelected()) { + + if (!device.meta().hasNode("storage")) { + device.getLogger().info("Storage not defined. Starting storage selection dialog"); + DirectoryChooser chooser = new DirectoryChooser(); + File storageDir = chooser.showDialog(this.plotPane.getScene().getWindow()); + if (storageDir == null) { + storeButton.setSelected(false); + throw new RuntimeException("User canceled directory selection"); + } + device.getConfig().putNode(new MetaBuilder("storage") + .putValue("path", storageDir.getAbsolutePath())); + } + Meta storageConfig = device.meta().getNode("storage"); + Storage localStorage = StorageManager.buildFrom(device.getContext()) + .buildStorage(storageConfig); + + String runName = device.meta().getString("numass.run", ""); + Meta meta = device.meta(); + if (meta.hasNode("numass")) { + try { + device.getLogger().info("Obtaining run information from cetral server..."); + NumassClient client = new NumassClient(meta.getString("numass.ip", "192.168.111.1"), + meta.getInt("numass.port", 8335)); + runName = client.getCurrentRun().getString("path", ""); + device.getLogger().info("Run name is '{}'", runName); + } catch (Exception ex) { + device.getLogger().warn("Failed to download current run information", ex); + } + } + + if (!runName.isEmpty()) { + try { + localStorage = localStorage.buildShelf(runName, null); + } catch (StorageException ex) { + device.getLogger().error("Failed to create storage shelf. Using root storage instead"); + } + } + + connection = new StorageConnection(localStorage); + device.connect(connection, Roles.STORAGE_ROLE); + } else if (connection != null) { + device.disconnect(connection); + } + } + } diff --git a/numass-control/msp/src/main/resources/fxml/MspView.fxml b/numass-control/msp/src/main/resources/fxml/MspView.fxml index 551f6155..fd8b6bc3 100644 --- a/numass-control/msp/src/main/resources/fxml/MspView.fxml +++ b/numass-control/msp/src/main/resources/fxml/MspView.fxml @@ -1,58 +1,56 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/app/ReadVac.java b/numass-control/vac/src/main/java/inr/numass/readvac/app/ReadVac.java index e4fab889..cbba4b0c 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/app/ReadVac.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/app/ReadVac.java @@ -81,7 +81,7 @@ public class ReadVac extends Application { controller.setLoaderFactory((VacCollectorDevice device, Storage localStorage) -> { try { - String runName = device.meta().getString("storage.run", ""); + String runName = device.meta().getString("numass.run", ""); if (config.hasNode("numass")) { try { logger.info("Obtaining run information from cetral server..."); diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacCollectorController.java b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacCollectorController.java index 5093319e..59670d8b 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacCollectorController.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacCollectorController.java @@ -5,8 +5,7 @@ */ package inr.numass.readvac.fx; -import de.jensd.shichimifx.utils.ConsoleDude; -import hep.dataforge.control.connections.Connection; +import hep.dataforge.control.connections.LoaderConnection; import hep.dataforge.control.connections.Roles; import hep.dataforge.control.devices.Device; import hep.dataforge.control.devices.DeviceListener; @@ -16,7 +15,7 @@ import hep.dataforge.control.measurements.Sensor; import hep.dataforge.points.DataPoint; import hep.dataforge.exceptions.ControlException; import hep.dataforge.exceptions.MeasurementException; -import hep.dataforge.exceptions.StorageException; +import hep.dataforge.fx.ConsoleWindow; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; import hep.dataforge.plots.PlotFrame; @@ -25,7 +24,6 @@ import hep.dataforge.plots.data.DynamicPlottableSet; import hep.dataforge.plots.fx.PlotContainer; import hep.dataforge.plots.jfreechart.JFreeChartFrame; import hep.dataforge.points.FormatBuilder; -import hep.dataforge.points.PointListener; import hep.dataforge.storage.api.PointLoader; import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.commons.LoaderFactory; @@ -49,16 +47,12 @@ import javafx.collections.FXCollections; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; -import javafx.scene.Scene; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; -import javafx.scene.control.TextArea; import javafx.scene.control.ToggleButton; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; import javafx.stage.DirectoryChooser; -import javafx.stage.Stage; -import javafx.stage.WindowEvent; import javafx.util.Duration; import org.controlsfx.control.Notifications; import org.slf4j.Logger; @@ -86,9 +80,8 @@ public class VacCollectorController implements Initializable, DeviceListener, Me private DynamicPlottableSet plottables; private BiFunction loaderFactory; - private TextArea consolePane; - private Stage consoleWindow; - + ConsoleWindow consoleWindow; + @FXML private AnchorPane plotHolder; @FXML @@ -122,20 +115,8 @@ public class VacCollectorController implements Initializable, DeviceListener, Me } }); - consolePane = new TextArea(); - consolePane.setEditable(false); - consolePane.setWrapText(true); -// consolePane.textProperty().addListener((ObservableValue observable, String oldValue, String newValue) -> { -// if (newValue.length() > 10000) { -// consolePane.clear(); -// } -// }); - consoleWindow = new Stage(); - consoleWindow.setTitle("Vacuum measurement console"); - consoleWindow.setScene(new Scene(consolePane, 800, 200)); - consoleWindow.setOnHidden((WindowEvent event) -> { - logButton.setSelected(false); - }); + consoleWindow = new ConsoleWindow(logButton); + consoleWindow.hookStd(); } @Override @@ -297,17 +278,6 @@ public class VacCollectorController implements Initializable, DeviceListener, Me } } - @FXML - private void onLogToggle(ActionEvent event) { - if (logButton.isSelected() && logButton.isSelected() != consoleWindow.isShowing()) { - consoleWindow.show(); - ConsoleDude.hookStdStreams(consolePane); - } else { - consoleWindow.hide(); - ConsoleDude.restoreStdStreams(); - } - } - /** * @return the logger */ @@ -324,39 +294,4 @@ public class VacCollectorController implements Initializable, DeviceListener, Me public void setLogger(Logger logger) { this.logger = logger; } - - private class LoaderConnection implements PointListener, Connection { - - private final PointLoader loader; - - public LoaderConnection(PointLoader loader) { - this.loader = loader; - } - - @Override - public void accept(DataPoint point) { - try { - loader.push(point); - } catch (StorageException ex) { - getLogger().error("Error while pushing data", ex); - } - } - - @Override - public boolean isOpen() { - return loader.isOpen(); - } - - @Override - public void open(Device object) throws Exception { - loader.open(); - } - - @Override - public void close() throws Exception { - loader.close(); - } - - } - } diff --git a/numass-control/vac/src/main/resources/fxml/VacCollector.fxml b/numass-control/vac/src/main/resources/fxml/VacCollector.fxml index a7435bbf..13f9de23 100644 --- a/numass-control/vac/src/main/resources/fxml/VacCollector.fxml +++ b/numass-control/vac/src/main/resources/fxml/VacCollector.fxml @@ -1,11 +1,5 @@ - - - - - - @@ -19,7 +13,7 @@ - + @@ -38,7 +32,7 @@ - +