import ch.psi.pshell.ui.Panel; import ch.psi.utils.State; import java.util.ArrayList; import java.util.HashMap; import javax.swing.table.DefaultTableModel; /** * */ public class EnergyScan extends Panel { final DefaultTableModel model; public EnergyScan() { initComponents(); model = (DefaultTableModel) table.getModel(); } //Overridable callbacks @Override public void onInitialize(int runCount) { } @Override public void onStateChange(State state, State former) { buttonStart.setEnabled(state==State.Ready); buttonAbort.setEnabled(state.isProcessing()); } @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() { jScrollPane2 = new javax.swing.JScrollPane(); jEditorPane1 = new javax.swing.JEditorPane(); buttonStart = new javax.swing.JButton(); buttonAbort = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); table = new javax.swing.JTable(); buttonAdd = new javax.swing.JButton(); buttonDelete = new javax.swing.JButton(); jScrollPane2.setViewportView(jEditorPane1); buttonStart.setText("Start"); buttonStart.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonStartActionPerformed(evt); } }); buttonAbort.setText("Abort"); buttonAbort.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonAbortActionPerformed(evt); } }); table.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { }, new String [] { "Start", "End", "Step" } ) { Class[] types = new Class [] { java.lang.Double.class, java.lang.Double.class, java.lang.Double.class }; public Class getColumnClass(int columnIndex) { return types [columnIndex]; } }); jScrollPane1.setViewportView(table); buttonAdd.setText("Add"); buttonAdd.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonAddActionPerformed(evt); } }); buttonDelete.setText("Delete"); buttonDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonDeleteActionPerformed(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() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addContainerGap()) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonAdd) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonDelete) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAdd, buttonDelete}); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonAdd) .addComponent(buttonDelete)) .addContainerGap()) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addContainerGap(79, Short.MAX_VALUE) .addComponent(buttonStart) .addGap(45, 45, 45) .addComponent(buttonAbort) .addContainerGap(79, Short.MAX_VALUE)) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonStart}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonStart) .addComponent(buttonAbort)) .addGap(4, 4, 4)) ); }// //GEN-END:initComponents private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed HashMap args = new HashMap(); ArrayList regions = new ArrayList(); for (int i=0; i< model.getRowCount(); i++){ ArrayList region = new ArrayList(); region.add(model.getValueAt(i, 0)); region.add(model.getValueAt(i, 1)); region.add(model.getValueAt(i, 2)); regions.add(region); } args.put("REGIONS", regions); try{ this.runAsync("templates/EnergyScan", args).handle((ret,ex)->{ if (ex!=null){ } return ret; }); } catch (Exception ex){ showException(ex); } }//GEN-LAST:event_buttonStartActionPerformed 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 buttonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddActionPerformed model.addRow(new Object[]{Double.NaN, Double.NaN, Double.NaN}); }//GEN-LAST:event_buttonAddActionPerformed private void buttonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDeleteActionPerformed if ((model.getRowCount()>0) && (table.getSelectedRow()>=0)){ model.removeRow(table.getSelectedRow()); } }//GEN-LAST:event_buttonDeleteActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buttonAbort; private javax.swing.JButton buttonAdd; private javax.swing.JButton buttonDelete; private javax.swing.JButton buttonStart; private javax.swing.JEditorPane jEditorPane1; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTable table; // End of variables declaration//GEN-END:variables }