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") + //