/* * Copyright (c) 2014-2018 Paul Scherrer Institute. All rights reserved. */ import ch.psi.pshell.core.Context; import ch.psi.pshell.plot.TimePlotBase; import ch.psi.pshell.ui.StripChart; import ch.psi.pshell.ui.App; import ch.psi.pshell.ui.Panel; import ch.psi.utils.State; import ch.psi.utils.swing.SwingUtils; import java.awt.Dimension; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; /** * */ public class LN2 extends Panel { final StripChart stripChart; TimePlotBase plot; public LN2() { initComponents(); stripChart = new StripChart(this.getTopLevel(), false, App.getStripChartFolderArg()); panel.add(stripChart.getPlotPanel()); try { stripChart.open(new File(Context.getInstance().getSetup().expandPath("{home}/stripchart/LN2_Monitoring.scd"))); stripChart.start(); } catch (Exception ex) { showException(ex); Logger.getLogger(LN2.class.getName()).log(Level.WARNING, null, ex); } plot = (TimePlotBase) SwingUtils.getComponentsByType(stripChart.getPlotPanel(),TimePlotBase.class)[0]; } //Overridable callbacks @Override public void onInitialize(int runCount) { } @Override public void onStop() { //saveImage(); super.onStop(); } @Override public void onStateChange(State state, State former) { if ( (state == State.Closing) || ((state == State.Initializing) && (former != State.Invalid)) ){ saveImage(); } } @Override public void onExecutedFile(String fileName, Object result) { } public void saveImage(){ getLogger().severe("Saving image"); try { String fileName = new File(getContext().getSetup().expandPath("{images}/ln2/{date}_{time}.png")).getCanonicalPath(); getLogger().severe("File: " + fileName); plot.saveSnapshot(fileName, "png", new Dimension(1200,800)); } catch (Exception ex) { getLogger().log(Level.SEVERE, null, ex); } getLogger().severe("Done"); } //Callback to perform update - in event thread @Override protected void doUpdate() { } @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { panel = new javax.swing.JPanel(); panel.setLayout(new java.awt.BorderLayout()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel panel; // End of variables declaration//GEN-END:variables }