/* * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ import ch.psi.pshell.core.Context; import ch.psi.pshell.plot.LinePlot; import ch.psi.pshell.ui.Panel; import ch.psi.utils.State; import java.awt.Component; import java.util.HashMap; import javax.swing.JPanel; /** * */ public class LaserGunAlignment extends Panel { public LaserGunAlignment() { initComponents(); centroidPlot.setStyle(LinePlot.Style.ErrorXY); setPersistedComponents(new Component[]{spinnerI1, spinnerI2, spinnerStep, spinnerSettlingTime, checkSaveImages, spinnerNumImages, spinnerNumBackgrounds, checkBackground, radioBackSimple, radioBackMultiple}); centroidPlot.clear(); } boolean running; //Overridable callbacks /* @Override public void onInitialize(int runCount) { if (runCount==0){ try { evalAsync("kill_camtool()", true).handle((ret, ex) -> { if (ex != null) { showException((Exception) ex); } return ret; }); } catch (Context.ContextStateException ex) { showException((Exception) ex); } } } */ @Override public void onStateChange(State state, State former) { buttonAbort.setEnabled(state == State.Busy); buttonRun.setEnabled(state == State.Ready); buttonClear.setEnabled(state == State.Ready); if (state != State.Busy) { running = false; } for (Component c : panelParameters.getComponents()) { if (!(c instanceof JPanel)) { c.setEnabled(state == State.Ready); } } if (state == State.Ready) { checkBackgroundActionPerformed(null); } } @Override public void onExecutedFile(String fileName, Object result) { } //Callback to perform update - in event thread @Override protected void doUpdate() { } @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { buttonGroupBack = new javax.swing.ButtonGroup(); buttonRun = new javax.swing.JButton(); buttonAbort = new javax.swing.JButton(); panelParameters = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); spinnerI1 = new javax.swing.JSpinner(); jLabel2 = new javax.swing.JLabel(); spinnerI2 = new javax.swing.JSpinner(); jLabel3 = new javax.swing.JLabel(); spinnerStep = new javax.swing.JSpinner(); jLabel4 = new javax.swing.JLabel(); spinnerSettlingTime = new javax.swing.JSpinner(); checkSaveImages = new javax.swing.JCheckBox(); spinnerNumBackgrounds = new javax.swing.JSpinner(); jLabel5 = new javax.swing.JLabel(); checkBackground = new javax.swing.JCheckBox(); radioBackSimple = new javax.swing.JRadioButton(); radioBackMultiple = new javax.swing.JRadioButton(); jLabel6 = new javax.swing.JLabel(); spinnerNumImages = new javax.swing.JSpinner(); jLabel7 = new javax.swing.JLabel(); comboSource = new javax.swing.JComboBox(); centroidPlot = new ch.psi.pshell.plot.LinePlotJFree(); buttonClear = new javax.swing.JButton(); buttonRun.setText("Run"); buttonRun.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonRunActionPerformed(evt); } }); buttonAbort.setText("Abort"); buttonAbort.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonAbortActionPerformed(evt); } }); panelParameters.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters")); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel1.setText("phi_start"); spinnerI1.setModel(new javax.swing.SpinnerNumberModel(95.0d, -360.0d, 360.0d, 1.0d)); jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel2.setText("phi_end:"); spinnerI2.setModel(new javax.swing.SpinnerNumberModel(100.0d, -360.0d, 360.0d, 1.0d)); jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel3.setText("Step size:"); spinnerStep.setModel(new javax.swing.SpinnerNumberModel(1.0d, 0.01d, 10.0d, 1.0d)); spinnerStep.setName("spinnerStep"); // NOI18N jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel4.setText("Settling time:"); spinnerSettlingTime.setModel(new javax.swing.SpinnerNumberModel(0.1d, 0.0d, 10.0d, 1.0d)); checkSaveImages.setText("Save images"); spinnerNumBackgrounds.setModel(new javax.swing.SpinnerNumberModel(5, 1, 100, 1)); jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel5.setText("Number of backgrounds:"); checkBackground.setSelected(true); checkBackground.setText("Background:"); checkBackground.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { checkBackgroundActionPerformed(evt); } }); buttonGroupBack.add(radioBackSimple); radioBackSimple.setText("Simple"); buttonGroupBack.add(radioBackMultiple); radioBackMultiple.setSelected(true); radioBackMultiple.setText("Multiple"); jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel6.setText("Number of images:"); spinnerNumImages.setModel(new javax.swing.SpinnerNumberModel(1, 1, 100, 1)); jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); jLabel7.setText("Source:"); comboSource.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "server", "camtool", "direct", "bpm" })); javax.swing.GroupLayout panelParametersLayout = new javax.swing.GroupLayout(panelParameters); panelParameters.setLayout(panelParametersLayout); panelParametersLayout.setHorizontalGroup( panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelParametersLayout.createSequentialGroup() .addGap(12, 12, 12) .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(checkBackground) .addComponent(checkSaveImages)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(panelParametersLayout.createSequentialGroup() .addGap(47, 47, 47) .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(radioBackMultiple) .addComponent(radioBackSimple)) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(panelParametersLayout.createSequentialGroup() .addContainerGap() .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelParametersLayout.createSequentialGroup() .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelParametersLayout.createSequentialGroup() .addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)) .addGroup(panelParametersLayout.createSequentialGroup() .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(spinnerNumImages, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(spinnerStep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(spinnerSettlingTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(spinnerNumBackgrounds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(spinnerI1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(spinnerI2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelParametersLayout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(comboSource, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); panelParametersLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerI1, spinnerI2, spinnerNumBackgrounds, spinnerNumImages, spinnerSettlingTime, spinnerStep}); panelParametersLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3, jLabel4, jLabel5, jLabel6}); panelParametersLayout.setVerticalGroup( panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelParametersLayout.createSequentialGroup() .addGap(18, 18, 18) .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(spinnerI1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(spinnerI2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(spinnerStep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(spinnerSettlingTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(4, 4, 4) .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6) .addComponent(spinnerNumImages, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(checkBackground) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(radioBackSimple) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(radioBackMultiple) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(spinnerNumBackgrounds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(checkSaveImages) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 98, Short.MAX_VALUE) .addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(comboSource, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7)) .addContainerGap()) ); centroidPlot.setLegendVisible(true); centroidPlot.setTitle(""); centroidPlot.setTitleFont(new java.awt.Font("DejaVu Sans", 0, 14)); // NOI18N buttonClear.setText("Clear"); buttonClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonClearActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(panelParameters, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(buttonRun, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(buttonAbort, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonClear)) .addComponent(centroidPlot, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)) .addContainerGap()) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonClear, buttonRun}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonRun) .addComponent(buttonAbort) .addComponent(buttonClear)) .addGap(18, 18, 18) .addComponent(centroidPlot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(panelParameters, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) ); }// //GEN-END:initComponents //((Plugin)this) private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed try { abort(); } catch (Exception ex) { showException(ex); } }//GEN-LAST:event_buttonAbortActionPerformed private void buttonRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRunActionPerformed try { running = true; HashMap args = new HashMap(); args.put("phi1", spinnerI1.getValue()); args.put("phi2", spinnerI2.getValue()); args.put("dphi", spinnerStep.getValue()); args.put("settling_time", spinnerSettlingTime.getValue()); args.put("plot_image", checkSaveImages.isSelected()); args.put("number_images", spinnerNumImages.getValue()); args.put("number_backgrounds", spinnerNumBackgrounds.getValue()); args.put("use_background", checkBackground.isSelected()); args.put("multiple_background", radioBackMultiple.isSelected()); args.put("centroid_plot", centroidPlot); args.put("source", comboSource.getSelectedItem().toString()); runAsync("Alignment/Laser_gun_alignment", args).handle((ret, ex) -> { if (ex != null) { getLogger().info("Exception executing scan: " + ex); showException((Exception) ex); } else { } running = false; return ret; }); } catch (Exception ex) { System.err.println(ex); running = false; showException(ex); } }//GEN-LAST:event_buttonRunActionPerformed private void checkBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBackgroundActionPerformed radioBackMultiple.setEnabled(checkBackground.isSelected()); radioBackSimple.setEnabled(checkBackground.isSelected()); spinnerNumBackgrounds.setEnabled(checkBackground.isSelected()); }//GEN-LAST:event_checkBackgroundActionPerformed private void buttonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClearActionPerformed try { centroidPlot.clear(); } catch (Exception ex) { showException(ex); } }//GEN-LAST:event_buttonClearActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buttonAbort; private javax.swing.JButton buttonClear; private javax.swing.ButtonGroup buttonGroupBack; private javax.swing.JButton buttonRun; private ch.psi.pshell.plot.LinePlotJFree centroidPlot; private javax.swing.JCheckBox checkBackground; private javax.swing.JCheckBox checkSaveImages; private javax.swing.JComboBox comboSource; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JPanel panelParameters; private javax.swing.JRadioButton radioBackMultiple; private javax.swing.JRadioButton radioBackSimple; private javax.swing.JSpinner spinnerI1; private javax.swing.JSpinner spinnerI2; private javax.swing.JSpinner spinnerNumBackgrounds; private javax.swing.JSpinner spinnerNumImages; private javax.swing.JSpinner spinnerSettlingTime; private javax.swing.JSpinner spinnerStep; // End of variables declaration//GEN-END:variables }