import ch.psi.pshell.device.Device; import ch.psi.pshell.device.DeviceAdapter; import ch.psi.pshell.device.DeviceListener; import ch.psi.pshell.ui.Panel; import ch.psi.utils.EncoderJson; import ch.psi.utils.State; import ch.psi.utils.swing.ScriptDialog; import java.nio.file.Paths; import java.util.Map; /** * */ public class Eiger extends Panel { final String RENDERER_PERSIST_FILE = "{context}/EigerRenderer"; Device detector; Device stddaq; public Eiger() { initComponents(); renderer.setPersistenceFile(Paths.get(getContext().getSetup().expandPath(RENDERER_PERSIST_FILE))); } final DeviceListener deviceListener = new DeviceAdapter() { @Override public void onStateChanged(Device device, State state, State former) { updateControls(); } }; //Overridable callbacks @Override public void onInitialize(int runCount) { detector = (Device) getDevice("detector"); stddaq = (Device) getDevice("std_daq"); if (detector!=null){ detector.addListener(deviceListener); } if (stddaq!=null){ stddaq.addListener(deviceListener); } updateControls(); } void updateControls(){ boolean enabled = getState().isReady(); buttonStart.setEnabled(enabled && ((stddaq!=null) && (stddaq.getState().isReady()))); buttonStop.setEnabled(enabled && ((stddaq!=null) && (stddaq.getState()==State.Busy))); buttonConfig.setEnabled(enabled && ((stddaq!=null) && (stddaq.getState().isInitialized()))); textFile.setEnabled(buttonStart.isEnabled()); spinnerImages.setEnabled(buttonStart.isEnabled()); buttonStartDet.setEnabled(enabled && ((detector!=null) && (detector.getState().isReady()))); buttonStopDet.setEnabled(enabled && ((detector!=null) && (detector.getState()==State.Busy))); buttonApplyConfigDet.setEnabled(buttonStartDet.isEnabled()); buttonConfigDet.setEnabled(enabled && ((detector!=null) && (detector.getState().isInitialized()))); buttonParsDet.setEnabled(enabled && ((detector!=null) && (detector.getState().isInitialized()))); } @Override public void onStateChange(State state, State former) { updateControls(); } @Override public void onExecutedFile(String fileName, Object result) { } @Override protected void onTimer() { } @Override protected void onLoaded() { } @Override protected void onUnloaded() { } //Invoked by 'update()' to update components in the event thread @Override protected void doUpdate() { } @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); buttonStartDet = new javax.swing.JButton(); buttonStopDet = new javax.swing.JButton(); buttonConfigDet = new javax.swing.JButton(); deviceStatePanel2 = new ch.psi.pshell.swing.DeviceStatePanel(); buttonParsDet = new javax.swing.JButton(); buttonApplyConfigDet = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); renderer = new ch.psi.pshell.imaging.Renderer(); jPanel3 = new javax.swing.JPanel(); buttonStart = new javax.swing.JButton(); buttonStop = new javax.swing.JButton(); buttonConfig = new javax.swing.JButton(); deviceStatePanel1 = new ch.psi.pshell.swing.DeviceStatePanel(); jLabel1 = new javax.swing.JLabel(); spinnerImages = new javax.swing.JSpinner(); jLabel2 = new javax.swing.JLabel(); textFile = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); deviceValuePanel1 = new ch.psi.pshell.swing.DeviceValuePanel(); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Detector"))); buttonStartDet.setText("Start"); buttonStartDet.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonStartDetActionPerformed(evt); } }); buttonStopDet.setText("Stop"); buttonStopDet.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonStopDetActionPerformed(evt); } }); buttonConfigDet.setText("Configuration"); buttonConfigDet.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonConfigDetActionPerformed(evt); } }); deviceStatePanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("State")); deviceStatePanel2.setDeviceName("detector"); buttonParsDet.setText("Parameters"); buttonParsDet.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonParsDetActionPerformed(evt); } }); buttonApplyConfigDet.setText("Apply Config"); buttonApplyConfigDet.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonApplyConfigDetActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(deviceStatePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(buttonConfigDet, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonStartDet, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonStopDet, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonParsDet, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonApplyConfigDet, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()))) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(buttonStartDet) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonStopDet) .addGap(18, 18, Short.MAX_VALUE) .addComponent(buttonApplyConfigDet) .addGap(18, 18, Short.MAX_VALUE) .addComponent(buttonConfigDet) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonParsDet) .addGap(18, 18, Short.MAX_VALUE) .addComponent(deviceStatePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Stream")); renderer.setDeviceName("image"); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Detector"), "STD DAQ")); buttonStart.setText("Start"); buttonStart.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonStartActionPerformed(evt); } }); buttonStop.setText("Abort"); buttonStop.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonStopActionPerformed(evt); } }); buttonConfig.setText("Configuration"); buttonConfig.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonConfigActionPerformed(evt); } }); deviceStatePanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("State")); deviceStatePanel1.setDeviceName("std_daq"); jLabel1.setText("Images:"); spinnerImages.setModel(new javax.swing.SpinnerNumberModel(10, 0, 100000, 1)); jLabel2.setText("File:"); textFile.setHorizontalAlignment(javax.swing.JTextField.RIGHT); textFile.setText("/tmp/test.h5"); jLabel3.setText("Req Id:"); deviceValuePanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("")); deviceValuePanel1.setDeviceName("std_daq"); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(buttonConfig, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(deviceStatePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonStart, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonStop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addComponent(jLabel1) .addGap(6, 6, 6)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(spinnerImages, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE) .addComponent(textFile, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(deviceValuePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 109, Short.MAX_VALUE))))) .addContainerGap()) ); jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {deviceValuePanel1, spinnerImages, textFile}); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(spinnerImages, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(textFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonStart) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(deviceValuePanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonStop) .addGap(18, 18, Short.MAX_VALUE) .addComponent(buttonConfig) .addGap(18, 18, Short.MAX_VALUE) .addComponent(deviceStatePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(0, 0, 0)) ); }// //GEN-END:initComponents private void buttonConfigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigActionPerformed try{ if (stddaq!=null){ String title = "Std Daq Config"; this.evalAsync("std_daq.get_config()").handle((ret,ex)->{ if (ex!=null){ showException((Exception) ex); } else { try{ Map cfg = (Map) ret; String json = EncoderJson.encode(cfg, true); ScriptDialog dlg = new ScriptDialog(getWindow(), true, title, json, "json"); dlg.setVisible(true); if (dlg.getResult()){ json = dlg.getText(); cfg = (Map) EncoderJson.decode(json, Map.class); setGlobalVar("_daq_config", cfg); evalAsync("std_daq.set_config(_daq_config)").handle((r,e)->{ if (e!=null){ showException((Exception) e); } else { showMessage(title, "Success updating config"); } return ret; }); } } catch (Exception e){ showException(e); } } return ret; }); } } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonConfigActionPerformed private void buttonConfigDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigDetActionPerformed try{ if (stddaq!=null){ String title = "Detector Config"; this.evalAsync("detector.get_config()").handle((ret,ex)->{ if (ex!=null){ showException((Exception) ex); } else { try{ Map cfg = (Map) ret; String json = EncoderJson.encode(cfg, true); ScriptDialog dlg = new ScriptDialog(getWindow(), true, title, json, "json"); dlg.setVisible(true); if (dlg.getResult()){ json = dlg.getText(); cfg = (Map) EncoderJson.decode(json, Map.class); setGlobalVar("_detector_config", cfg); evalAsync("detector.set_config(_detector_config)").handle((r,e)->{ if (e!=null){ showException((Exception) e); } else { showMessage(title, "Success updating config"); } return ret; }); } } catch (Exception e){ showException(e); } } return ret; }); } } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonConfigDetActionPerformed private void buttonParsDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonParsDetActionPerformed try{ if (stddaq!=null){ String title = "Detector Parameters"; this.evalAsync("detector.get_pars()").handle((ret,ex)->{ if (ex!=null){ showException((Exception) ex); } else { try{ Map cfg = (Map) ret; String json = EncoderJson.encode(cfg, true); ScriptDialog dlg = new ScriptDialog(getWindow(), true, title, json, "json"); dlg.setVisible(true); if (dlg.getResult()){ json = dlg.getText(); cfg = (Map) EncoderJson.decode(json, Map.class); setGlobalVar("_detector_pars", cfg); evalAsync("detector.set_pars(_detector_pars)").handle((r,e)->{ if (e!=null){ showException((Exception) e); } else { showMessage(title, "Success updating parameters"); } return ret; }); } } catch (Exception e){ showException(e); } } return ret; }); } } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonParsDetActionPerformed private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed try{ if (stddaq!=null){ int images = (Integer)spinnerImages.getValue(); String file = textFile.getText(); evalAsync("std_daq.start(" + images + ", '" + file + "')").handle((r,e)->{ if (e!=null){ showException((Exception) e); } return r; }); } } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonStartActionPerformed private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed try{ if (stddaq!=null){ evalAsync("std_daq.abort()").handle((r,e)->{ if (e!=null){ showException((Exception) e); } return r; }); } } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonStopActionPerformed private void buttonStartDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartDetActionPerformed try{ if (stddaq!=null){ evalAsync("detector.start()").handle((r,e)->{ if (e!=null){ showException((Exception) e); } return r; }); } } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonStartDetActionPerformed private void buttonStopDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopDetActionPerformed try{ if (stddaq!=null){ evalAsync("detector.stop()").handle((r,e)->{ if (e!=null){ showException((Exception) e); } return r; }); } } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonStopDetActionPerformed private void buttonApplyConfigDetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyConfigDetActionPerformed try{ if (stddaq!=null){ evalAsync("detector.apply_config()").handle((r,e)->{ if (e!=null){ showException((Exception) e); } return r; }); } } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonApplyConfigDetActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buttonApplyConfigDet; private javax.swing.JButton buttonConfig; private javax.swing.JButton buttonConfigDet; private javax.swing.JButton buttonParsDet; private javax.swing.JButton buttonStart; private javax.swing.JButton buttonStartDet; private javax.swing.JButton buttonStop; private javax.swing.JButton buttonStopDet; private ch.psi.pshell.swing.DeviceStatePanel deviceStatePanel1; private ch.psi.pshell.swing.DeviceStatePanel deviceStatePanel2; private ch.psi.pshell.swing.DeviceValuePanel deviceValuePanel1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private ch.psi.pshell.imaging.Renderer renderer; private javax.swing.JSpinner spinnerImages; private javax.swing.JTextField textFile; // End of variables declaration//GEN-END:variables }