/* * 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; @Override protected JPanel create() { panel = new PluginPanel(); return panel; } @Override protected void onInitialize(int runCount) { 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) { update(); } }); update(); } @Override protected void doUpdate() { 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 } }