From 54a5371e7bb6eab27755478396cf15b1db1a915f Mon Sep 17 00:00:00 2001 From: x07maop Date: Thu, 28 May 2015 09:17:22 +0200 Subject: [PATCH] Startup --- .gitignore | 2 +- plugins/EnergyScan.form | 70 +++++++++++++++++ plugins/EnergyScan.java | 166 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 plugins/EnergyScan.form create mode 100644 plugins/EnergyScan.java diff --git a/.gitignore b/.gitignore index adb0257..3a07d4d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,10 +2,10 @@ /sessions /context /log -/plugins /extensions /www script/cachedir script/Lib script/*.class script/*.pyc +plugins/*.class diff --git a/plugins/EnergyScan.form b/plugins/EnergyScan.form new file mode 100644 index 0000000..c45f38e --- /dev/null +++ b/plugins/EnergyScan.form @@ -0,0 +1,70 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/EnergyScan.java b/plugins/EnergyScan.java new file mode 100644 index 0000000..1ab4f61 --- /dev/null +++ b/plugins/EnergyScan.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2014 Paul Scherrer Institute. All rights reserved. + */ + +import ch.psi.pshell.dev.Device; +import ch.psi.pshell.dev.DeviceBase; +import ch.psi.pshell.dev.DeviceListener; +import ch.psi.pshell.epics.ChannelDoubleArray; +import ch.psi.pshell.epics.ChannelInteger; +import ch.psi.pshell.plot.LinePlotBase; +import ch.psi.pshell.plot.LinePlotJFree; +import ch.psi.pshell.plot.LinePlotSeries; +import ch.psi.utils.swing.MonitoredPanel; +import ch.psi.pshell.ui.Panel; +import ch.psi.utils.State; +import ch.psi.utils.swing.SwingUtils; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +/** + * + */ +public class EnergyScan extends Panel { + + PluginPanel panel; + ChannelDoubleArray data; + ChannelDoubleArray edata; + ChannelInteger count; + + volatile boolean requestedPlotting; + @Override + protected JPanel create() { + panel = new PluginPanel(); + return panel; + } + + @Override + protected void onInitialize() { + super.onInitialize(); + + count = (ChannelInteger) getController().getDevicePool().getByName("count"); + data = (ChannelDoubleArray) getController().getDevicePool().getByName("data"); + edata = (ChannelDoubleArray) getController().getDevicePool().getByName("edata"); + + getController().getDevicePool().getByName("count").addListener(new DeviceListener() { + @Override + public void onStateChanged(Device device, State state, State former) { + } + + @Override + public void onValueChanged(Device device, Object value, Object former) { + if (!requestedPlotting){ + requestedPlotting = true; + SwingUtilities.invokeLater(() -> { + panel.plot(); + }); + } + } + }); + panel.plot(); + } + + public class PluginPanel extends MonitoredPanel { + + final LinePlotBase plot; + final LinePlotSeries series; + + public PluginPanel() { + initComponents(); + plot = new LinePlotJFree(); + plot.setTitle(""); + series = new LinePlotSeries("data"); + plot.addSeries(series); + panelPlot.add(plot); + } + + void plot(){ + try{ + requestedPlotting=false; + Integer c = count.take(); + if (c == null){ + series.clear(); + } else { + data.setSize(c); + edata.setSize(c); + series.setData(edata.read(), data.read()); + } + } catch (Exception ex){ + SwingUtils.showException(this, ex); + } + } + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + buttonExecute = new javax.swing.JButton(); + buttonAbort = new javax.swing.JButton(); + panelPlot = new javax.swing.JPanel(); + + buttonExecute.setText("Start"); + buttonExecute.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonExecuteActionPerformed(evt); + } + }); + + buttonAbort.setText("Stop"); + buttonAbort.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAbortActionPerformed(evt); + } + }); + + panelPlot.setLayout(new java.awt.BorderLayout()); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(31, 31, 31) + .addComponent(buttonExecute) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(buttonAbort, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(269, Short.MAX_VALUE)) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(panelPlot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonExecute}); + + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(27, 27, 27) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonExecute) + .addComponent(buttonAbort)) + .addGap(28, 28, 28) + .addComponent(panelPlot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void buttonExecuteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExecuteActionPerformed + try { + run("test1"); + } catch (Exception ex) { + SwingUtils.showException(this, ex); + } + }//GEN-LAST:event_buttonExecuteActionPerformed + + private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed + getController().abort(); + }//GEN-LAST:event_buttonAbortActionPerformed + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonAbort; + private javax.swing.JButton buttonExecute; + private javax.swing.JPanel panelPlot; + // End of variables declaration//GEN-END:variables + } +}