import ch.psi.pshell.epics.ChannelDouble; import ch.psi.pshell.epics.ChannelInteger; import ch.psi.pshell.ui.Panel; import ch.psi.utils.State; import java.io.IOException; /** * */ public class Eiger extends Panel { boolean updatingControls=true; ChannelInteger bitDepth; ChannelInteger mode; ChannelDouble exposure; public Eiger() { initComponents(); } void initializeDevices() throws IOException, InterruptedException{ } //Overridable callbacks @Override public void onInitialize(int runCount) { try { this.stopTimer(); renderer.clearOverlays(); bitDepth = ((ChannelInteger)getDevice("eiger_bit_depth")); mode = ((ChannelInteger) getDevice("eiger_mode")); exposure = ((ChannelDouble) getDevice("eiger_exposure")); startTimer(1000,10); } catch (Exception ex) { showException(ex); } } @Override public void onStateChange(State state, State former) { if (former==State.Initializing){ if (checkMeasurements.isSelected()){ checkMeasurementsActionPerformed(null); } } } @Override public void onExecutedFile(String fileName, Object result) { } @Override public void onTimer() { updatingControls=true; //initializeDevices(); try{ try{ String value = String.valueOf(bitDepth.take()); comboDepth.setSelectedItem(value); } catch (Exception ex){ comboDepth.setSelectedIndex(comboDepth.getItemCount()-1); //Set "Unknown" } try{ comboMode.setSelectedIndex(mode.take()); } catch (Exception ex){ } try{ spinnerExpusure.setValue(exposure.take()); } catch (Exception ex){ } comboDepth.setEnabled(bitDepth.isInitialized()); comboMode.setEnabled(mode.isInitialized()); spinnerExpusure.setEnabled(exposure.isInitialized()); } finally{ updatingControls=false; } } //Callback to perform update - in event thread @Override protected void doUpdate() { } @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { renderer = new ch.psi.pshell.imaging.Renderer(); jLabel1 = new javax.swing.JLabel(); comboDepth = new javax.swing.JComboBox<>(); buttonTriggerDetector = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); comboMode = new javax.swing.JComboBox<>(); jLabel3 = new javax.swing.JLabel(); spinnerExpusure = new javax.swing.JSpinner(); deviceValuePanel1 = new ch.psi.pshell.swing.DeviceValuePanel(); deviceValuePanel2 = new ch.psi.pshell.swing.DeviceValuePanel(); deviceValuePanel3 = new ch.psi.pshell.swing.DeviceValuePanel(); buttonStopDetector = new javax.swing.JButton(); deviceValuePanel4 = new ch.psi.pshell.swing.DeviceValuePanel(); buttonShowDetectorPanel = new javax.swing.JButton(); checkMeasurements = new javax.swing.JCheckBox(); renderer.setDeviceName("image"); renderer.setMode(ch.psi.pshell.imaging.RendererMode.Fit); jLabel1.setText("Bit Depth:"); comboDepth.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "4", "8", "16", "32", "Unknown" })); comboDepth.setEnabled(false); comboDepth.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { comboDepthActionPerformed(evt); } }); buttonTriggerDetector.setText("Start"); buttonTriggerDetector.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonTriggerDetectorActionPerformed(evt); } }); jLabel2.setText("Mode:"); comboMode.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Single", "Multiple", "Continuous" })); comboMode.setEnabled(false); comboMode.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { comboModeActionPerformed(evt); } }); jLabel3.setText("Exposure:"); spinnerExpusure.setModel(new javax.swing.SpinnerNumberModel(1.0d, 0.001d, 300.0d, 1.0d)); spinnerExpusure.setEnabled(false); spinnerExpusure.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { spinnerExpusureStateChanged(evt); } }); deviceValuePanel1.setDeviceName("eiger_mode_rbv"); deviceValuePanel2.setDeviceName("eiger_bit_depth_rbv"); deviceValuePanel3.setDeviceName("eiger_exposure_rbv"); buttonStopDetector.setText("Stop"); buttonStopDetector.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonStopDetectorActionPerformed(evt); } }); deviceValuePanel4.setDeviceName("eiger_status"); buttonShowDetectorPanel.setText("Control Panel"); buttonShowDetectorPanel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonShowDetectorPanelActionPerformed(evt); } }); checkMeasurements.setText("Measurements"); checkMeasurements.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { checkMeasurementsActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(comboMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(deviceValuePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(buttonShowDetectorPanel)) .addGroup(layout.createSequentialGroup() .addComponent(comboDepth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(deviceValuePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(spinnerExpusure, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(deviceValuePanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(checkMeasurements))) .addGap(18, 18, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(deviceValuePanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addComponent(buttonStopDetector, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonTriggerDetector, javax.swing.GroupLayout.Alignment.TRAILING))) .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(4, 4, 4)) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonStopDetector, buttonTriggerDetector, comboDepth, comboMode, deviceValuePanel1, deviceValuePanel2, deviceValuePanel3, deviceValuePanel4, spinnerExpusure}); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonShowDetectorPanel, checkMeasurements}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel2) .addComponent(comboMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(deviceValuePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(buttonShowDetectorPanel) .addComponent(buttonTriggerDetector)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel1) .addComponent(comboDepth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(deviceValuePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(buttonStopDetector)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) .addComponent(jLabel3) .addComponent(spinnerExpusure, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(deviceValuePanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(checkMeasurements) .addComponent(deviceValuePanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(renderer, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)) ); layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {buttonShowDetectorPanel, buttonStopDetector, buttonTriggerDetector, comboDepth, comboMode, deviceValuePanel1, deviceValuePanel2, deviceValuePanel3, deviceValuePanel4, spinnerExpusure}); }// //GEN-END:initComponents private void comboDepthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboDepthActionPerformed try{ if (!updatingControls){ if (comboDepth.getSelectedIndex()!=comboDepth.getItemCount()-1) { Integer value = Integer.valueOf((String)comboDepth.getSelectedItem()); bitDepth.write(value); } } } catch (Exception ex){ } }//GEN-LAST:event_comboDepthActionPerformed private void buttonTriggerDetectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTriggerDetectorActionPerformed try { evalAsync("eiger.start()"); } catch (Exception ex) { showException(ex); } }//GEN-LAST:event_buttonTriggerDetectorActionPerformed private void comboModeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboModeActionPerformed try{ if (!updatingControls){ Integer value = comboMode.getSelectedIndex(); mode.write(value); } } catch (Exception ex){ } }//GEN-LAST:event_comboModeActionPerformed private void spinnerExpusureStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerExpusureStateChanged try{ if (!updatingControls){ exposure.write((Double)spinnerExpusure.getValue()); } } catch (Exception ex){ } }//GEN-LAST:event_spinnerExpusureStateChanged private void buttonStopDetectorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopDetectorActionPerformed try { evalAsync("eiger.stop()"); } catch (Exception ex) { showException(ex); } }//GEN-LAST:event_buttonStopDetectorActionPerformed private void buttonShowDetectorPanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonShowDetectorPanelActionPerformed try { showDevicePanel("eiger"); } catch (Exception ex) { showException(ex); } }//GEN-LAST:event_buttonShowDetectorPanelActionPerformed private void checkMeasurementsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkMeasurementsActionPerformed try { if (checkMeasurements.isSelected()){ setGlobalVar("PLUGIN_RENDERER", renderer); evalAsync("start_measurements(renderer=PLUGIN_RENDERER)"); } else { evalAsync("stop_measurements()"); } } catch (Exception ex) { showException(ex); } }//GEN-LAST:event_checkMeasurementsActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buttonShowDetectorPanel; private javax.swing.JButton buttonStopDetector; private javax.swing.JButton buttonTriggerDetector; private javax.swing.JCheckBox checkMeasurements; private javax.swing.JComboBox comboDepth; private javax.swing.JComboBox comboMode; private ch.psi.pshell.swing.DeviceValuePanel deviceValuePanel1; private ch.psi.pshell.swing.DeviceValuePanel deviceValuePanel2; private ch.psi.pshell.swing.DeviceValuePanel deviceValuePanel3; private ch.psi.pshell.swing.DeviceValuePanel deviceValuePanel4; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private ch.psi.pshell.imaging.Renderer renderer; private javax.swing.JSpinner spinnerExpusure; // End of variables declaration//GEN-END:variables }