diff --git a/plugins/TestingPanel.form b/plugins/TestingPanel.form index 527454f..6f1e4c7 100644 --- a/plugins/TestingPanel.form +++ b/plugins/TestingPanel.form @@ -19,21 +19,34 @@ - - - + + + + + + + + + + + + + + + + + + + - - - @@ -51,11 +64,20 @@ - - - - + + + + + + + + + + + + + @@ -101,5 +123,17 @@ + + + + + + + + + + + + diff --git a/plugins/TestingPanel.java b/plugins/TestingPanel.java index 55292df..2d5ca85 100644 --- a/plugins/TestingPanel.java +++ b/plugins/TestingPanel.java @@ -3,11 +3,18 @@ */ 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; @@ -19,15 +26,35 @@ import javax.swing.JPanel; */ public class TestingPanel 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() { - return new NetbeansPluginPanel(); + protected JPanel create() { + getApp().addTask(task); + return new NetbeansPluginPanel(); + } @Override protected void onInitialize(int runCount){ - Motor motor = (Motor) TestingPanel.this.getDevice("motor"); - System.out.println("Device = " + motor); + motor = (Motor) TestingPanel.this.getDevice("motor"); motorPanel.setDevice(motor); } @@ -37,6 +64,16 @@ public class TestingPanel extends Panel { initComponents(); motorPanel = new MotorPanel(); panel.add(motorPanel); + onInitialize(-1); + + + plot = new LinePlotJFree(); + plot.setTitle(""); + panelPlot.add(plot); + + + series=new LinePlotSeries("Position"); + plot.addSeries(series); } @SuppressWarnings("unchecked") @@ -49,6 +86,8 @@ public class TestingPanel extends Panel { check = new javax.swing.JCheckBox(); spinner = new javax.swing.JSpinner(); panel = new javax.swing.JPanel(); + panelPlot = new javax.swing.JPanel(); + jButton2 = new javax.swing.JButton(); buttonExecute.setText("Execute"); buttonExecute.addActionListener(new java.awt.event.ActionListener() { @@ -77,6 +116,15 @@ public class TestingPanel extends Panel { panel.setLayout(new java.awt.BorderLayout()); + panelPlot.setLayout(new java.awt.BorderLayout()); + + jButton2.setText("Java Code"); + jButton2.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jButton2ActionPerformed(evt); + } + }); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -84,17 +132,26 @@ public class TestingPanel extends Panel { .addGroup(layout.createSequentialGroup() .addGap(31, 31, 31) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(jButton1) + .addGroup(layout.createSequentialGroup() + .addComponent(panelPlot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(check) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(buttonExecute, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonAbort, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addGap(99, 99, 99) - .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, 394, javax.swing.GroupLayout.PREFERRED_SIZE))) - .addContainerGap(74, Short.MAX_VALUE)) + .addComponent(buttonAbort, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(jButton1) + .addComponent(spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(87, 87, 87) + .addComponent(panel, javax.swing.GroupLayout.PREFERRED_SIZE, 394, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 178, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jButton2) + .addGap(270, 270, 270)))))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -108,11 +165,17 @@ public class TestingPanel extends Panel { .addGap(55, 55, 55) .addComponent(check)) .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(jButton1) - .addContainerGap(205, Short.MAX_VALUE)) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(spinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jButton1) + .addGap(18, 18, 18)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jButton2) + .addGap(26, 26, 26))) + .addComponent(panelPlot, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)) ); }// //GEN-END:initComponents @@ -171,12 +234,42 @@ public class TestingPanel extends Panel { }//GEN-LAST:event_jButton1ActionPerformed + private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + + getApp().startTask(task); + try { + task.start(TaskRunMode.async); + } catch (Exception ex) { + SwingUtils.showException(NetbeansPluginPanel.this, ex); + } + + /* + new Thread(() -> { + try { + 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); + } + } catch (Exception ex) { + SwingUtils.showException(NetbeansPluginPanel.this, ex); + } + }).start(); */ + + }//GEN-LAST:event_jButton2ActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buttonAbort; private javax.swing.JButton buttonExecute; private javax.swing.JCheckBox check; private javax.swing.JButton jButton1; + private javax.swing.JButton jButton2; private javax.swing.JPanel panel; + private javax.swing.JPanel panelPlot; private javax.swing.JSpinner spinner; // End of variables declaration//GEN-END:variables }