/* * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. */ import ch.psi.pshell.dev.Motor; import ch.psi.pshell.plot.LinePlotBase; import ch.psi.pshell.plot.LinePlotJFree; import ch.psi.pshell.plot.LinePlotSeries; import ch.psi.pshell.plot.Plot; import ch.psi.pshell.swing.MotorPanel; import ch.psi.pshell.ui.App; import ch.psi.utils.swing.MonitoredPanel; import ch.psi.pshell.ui.Panel; import ch.psi.utils.swing.SwingUtils; import ch.psi.wsaf.ApplicationStateException; import ch.psi.wsaf.Task; import ch.psi.wsaf.TaskRunMode; import ch.psi.wsaf.TaskRunningException; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JPanel; /** * */ public class TestingList extends Panel { MotorPanel motorPanel; LinePlotBase plot ; LinePlotSeries series; Motor motor; Task task = new Task() { @Override protected Object execute() throws Exception { series.clear(); for (int i=0;i<1000;i++){ double pos = motor.read(); Thread.sleep(2); plot.getAxis(Plot.AxisId.X).setRange(0, 1000); series.appendData(i, pos); } return true; } }; @Override protected JPanel create() { getApp().addTask(task); return new NetbeansPluginPanel(); } @Override protected void onInitialize(int runCount){ motor = (Motor) TestingList.this.getDevice("motor"); motorPanel.setDevice(motor); } public class NetbeansPluginPanel extends MonitoredPanel { @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { jScrollPane2 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); cmTestPS = new javax.swing.JButton(); jCheckBox1 = new javax.swing.JCheckBox(); jButton4 = new javax.swing.JButton(); txtTestPSRes = new javax.swing.JTextField(); jButton3 = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); txtOutput = new javax.swing.JTextArea(); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); jScrollPane2.setViewportView(jTable1); cmTestPS.setText("Test PS"); cmTestPS.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmTestPSActionPerformed(evt); } }); jCheckBox1.setActionCommand("check2"); jCheckBox1.setLabel("check2"); jCheckBox1.setName("check2"); // NOI18N jCheckBox1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jCheckBox1ActionPerformed(evt); } }); jButton4.setText("Test LS"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); jButton3.setText("jButton3"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); txtOutput.setColumns(20); txtOutput.setRows(5); jScrollPane1.setViewportView(txtOutput); 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) .addGroup(layout.createSequentialGroup() .addGap(33, 33, 33) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cmTestPS, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(293, 293, 293)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(58, 58, 58) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(84, 84, 84) .addComponent(txtTestPSRes, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(jCheckBox1) .addGap(0, 74, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(46, 46, 46) .addComponent(jCheckBox1)) .addComponent(jButton3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtTestPSRes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(cmTestPS)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton4)) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(542, Short.MAX_VALUE)) ); }// //GEN-END:initComponents private void cmTestPSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmTestPSActionPerformed try { boolean var1 = jCheckBox1.isSelected(); int var2 = 2;// (Integer)spinner.getValue(); int result; HashMap args = new HashMap(); args.put("relative", var1); args.put("steps", var2); run("power-supply", args); //try to print the result txtTestPSRes.setText(args.get("steps").toString()); //evalAsync("run('args', locals = {'relative':" + (var1 ? "True" :"False") + ", 'steps':" + var2 + "})"); } catch (Exception ex) { SwingUtils.showException(this, ex); } // TODO add your handling code here: }//GEN-LAST:event_cmTestPSActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed // TODO add your handling code here: try { boolean var1 = jCheckBox1.isSelected(); int var2 = 2;// (Integer)spinner.getValue(); HashMap args = new HashMap(); args.put("relative", var1); args.put("steps", var2); run("motor-slide", args); //evalAsync("run('args', locals = {'relative':" + (var1 ? "True" :"False") + ", 'steps':" + var2 + "})"); } catch (Exception ex) { SwingUtils.showException(this, ex); } // TODO add your handling code here: }//GEN-LAST:event_jButton4ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: txtOutput.setText("Working Directory = " + System.getProperty("user.dir")); }//GEN-LAST:event_jButton3ActionPerformed private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jCheckBox1ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cmTestPS; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JCheckBox jCheckBox1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTable jTable1; private javax.swing.JTextArea txtOutput; private javax.swing.JTextField txtTestPSRes; // End of variables declaration//GEN-END:variables } }