Startup
This commit is contained in:
358
plugins/ReturnBug.java
Normal file
358
plugins/ReturnBug.java
Normal file
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
* Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved.
|
||||
*/
|
||||
|
||||
import ch.psi.pshell.plot.LinePlotSeries;
|
||||
import ch.psi.pshell.plot.Plot;
|
||||
import ch.psi.pshell.scan.Scan;
|
||||
import ch.psi.pshell.scan.ScanListener;
|
||||
import ch.psi.pshell.scan.ScanRecord;
|
||||
import ch.psi.pshell.ui.Panel;
|
||||
import ch.psi.utils.State;
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ReturnBug extends Panel {
|
||||
LinePlotSeries series = new LinePlotSeries("Values");
|
||||
|
||||
public ReturnBug() {
|
||||
initComponents();
|
||||
plot.addSeries(series);
|
||||
plot.getAxis(Plot.AxisId.X).setLabel("Phase");
|
||||
plot.getAxis(Plot.AxisId.Y).setLabel("Charge");
|
||||
}
|
||||
|
||||
//Overridable callbacks
|
||||
@Override
|
||||
public void onInitialize(int runCount) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateChange(State state, State former) {
|
||||
buttonAbort.setEnabled(state.isProcessing());
|
||||
buttonStart.setEnabled(state == State.Ready);
|
||||
|
||||
spinnerStart.setEnabled(buttonStart.isEnabled());
|
||||
spinnerStop.setEnabled(buttonStart.isEnabled());
|
||||
spinnerStep.setEnabled(buttonStart.isEnabled());
|
||||
spinnerSamples.setEnabled(buttonStart.isEnabled());
|
||||
spinnerLatency.setEnabled(buttonStart.isEnabled());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecutedFile(String fileName, Object result) {
|
||||
}
|
||||
|
||||
|
||||
//Callback to perform update - in event thread
|
||||
@Override
|
||||
protected void doUpdate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
getContext().addScanListener(scanListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
getContext().removeScanListener(scanListener);
|
||||
super.onStop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
ScanListener scanListener = new ScanListener() {
|
||||
@Override
|
||||
public void onScanStarted(Scan scan, String plotTitle) {
|
||||
if ("ReturnBug".equals(getContext().getExecutionPars().getName())){
|
||||
series.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewRecord(Scan scan, ScanRecord record) {
|
||||
if ("ReturnBug".equals(getContext().getExecutionPars().getName())){
|
||||
series.appendData((Double)record.getPositions()[0], ((Number)record.getValues()[0]).doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanEnded(Scan scan, Exception ex) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
buttonStart = new javax.swing.JButton();
|
||||
buttonAbort = new javax.swing.JButton();
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
spinnerStep = new javax.swing.JSpinner();
|
||||
jLabel5 = new javax.swing.JLabel();
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
spinnerStop = new javax.swing.JSpinner();
|
||||
jLabel3 = new javax.swing.JLabel();
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
spinnerLatency = new javax.swing.JSpinner();
|
||||
spinnerSamples = new javax.swing.JSpinner();
|
||||
jLabel4 = new javax.swing.JLabel();
|
||||
spinnerStart = new javax.swing.JSpinner();
|
||||
plot = new ch.psi.pshell.plot.LinePlotJFree();
|
||||
jPanel2 = new javax.swing.JPanel();
|
||||
jLabel7 = new javax.swing.JLabel();
|
||||
spinnerPhaseRef = new javax.swing.JSpinner();
|
||||
|
||||
buttonStart.setText("Start");
|
||||
buttonStart.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonStartActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonAbort.setText("Abort");
|
||||
buttonAbort.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonAbortActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters"));
|
||||
|
||||
spinnerStep.setModel(new javax.swing.SpinnerNumberModel(5.0d, 0.1d, 90.0d, 1.0d));
|
||||
|
||||
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
||||
jLabel5.setText("Latency:");
|
||||
|
||||
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
||||
jLabel1.setText("Start:");
|
||||
|
||||
spinnerStop.setModel(new javax.swing.SpinnerNumberModel(360.0d, -45.0d, 360.0d, 1.0d));
|
||||
|
||||
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
||||
jLabel3.setText("Step:");
|
||||
|
||||
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
||||
jLabel2.setText("Stop:");
|
||||
|
||||
spinnerLatency.setModel(new javax.swing.SpinnerNumberModel(0.1d, 0.0d, 1.0d, 0.01d));
|
||||
|
||||
spinnerSamples.setModel(new javax.swing.SpinnerNumberModel(1, 1, 50, 1));
|
||||
|
||||
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
||||
jLabel4.setText("Nb Samples:");
|
||||
|
||||
spinnerStart.setModel(new javax.swing.SpinnerNumberModel(0.0d, -45.0d, 360.0d, 1.0d));
|
||||
|
||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||
jPanel1.setLayout(jPanel1Layout);
|
||||
jPanel1Layout.setHorizontalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addComponent(jLabel1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(spinnerStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addComponent(jLabel2)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(spinnerStop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addComponent(jLabel3)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(spinnerStep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addComponent(jLabel4)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(spinnerSamples, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addComponent(jLabel5)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(spinnerLatency, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3, jLabel4, jLabel5});
|
||||
|
||||
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerLatency, spinnerSamples, spinnerStart, spinnerStep, spinnerStop});
|
||||
|
||||
jPanel1Layout.setVerticalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel1)
|
||||
.addComponent(spinnerStart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel2)
|
||||
.addComponent(spinnerStop, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel3)
|
||||
.addComponent(spinnerStep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel4)
|
||||
.addComponent(spinnerSamples, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel5)
|
||||
.addComponent(spinnerLatency, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
plot.setTitle("");
|
||||
|
||||
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Output"));
|
||||
|
||||
jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
||||
jLabel7.setText("Ref Phase:");
|
||||
|
||||
spinnerPhaseRef.setModel(new javax.swing.SpinnerNumberModel(0.0d, -45.0d, 360.0d, 1.0d));
|
||||
spinnerPhaseRef.addChangeListener(new javax.swing.event.ChangeListener() {
|
||||
public void stateChanged(javax.swing.event.ChangeEvent evt) {
|
||||
spinnerPhaseRefStateChanged(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
||||
jPanel2.setLayout(jPanel2Layout);
|
||||
jPanel2Layout.setHorizontalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jLabel7)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(spinnerPhaseRef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
jPanel2Layout.setVerticalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(jLabel7)
|
||||
.addComponent(spinnerPhaseRef, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap(116, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonStart)
|
||||
.addGap(27, 27, 27)
|
||||
.addComponent(buttonAbort)
|
||||
.addGap(0, 411, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonStart});
|
||||
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
|
||||
.addGap(18, 18, 18))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(buttonStart)
|
||||
.addComponent(buttonAbort))
|
||||
.addGap(17, 17, 17))
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed
|
||||
//((Plugin)this).
|
||||
plot.removeMarker(null);
|
||||
spinnerPhaseRef.setValue(0.0);
|
||||
ArrayList parameters = new ArrayList();
|
||||
parameters.add(spinnerStart.getValue());
|
||||
parameters.add(spinnerStop.getValue());
|
||||
parameters.add(spinnerStep.getValue());
|
||||
parameters.add(spinnerSamples.getValue());
|
||||
parameters.add(spinnerLatency.getValue());
|
||||
try {
|
||||
//How to get a callback on the end of execution
|
||||
|
||||
runAsync("test/ReturnBug", parameters).handle((ret, ex) -> {
|
||||
if (ex != null){
|
||||
getLogger().info("Exception executing scan: " + ex);
|
||||
} else {
|
||||
spinnerPhaseRef.setValue(ret);
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
|
||||
|
||||
//runAsync("RFscan/ReturnBug", parameters);
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
|
||||
}//GEN-LAST:event_buttonStartActionPerformed
|
||||
|
||||
private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed
|
||||
try {
|
||||
abort();
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
}//GEN-LAST:event_buttonAbortActionPerformed
|
||||
|
||||
private void spinnerPhaseRefStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerPhaseRefStateChanged
|
||||
try {
|
||||
plot.removeMarker(null);
|
||||
plot.addMarker((Double)spinnerPhaseRef.getValue(), Plot.AxisId.X, "Ref Phase",Color.BLUE);
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
}//GEN-LAST:event_spinnerPhaseRefStateChanged
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton buttonAbort;
|
||||
private javax.swing.JButton buttonStart;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JLabel jLabel2;
|
||||
private javax.swing.JLabel jLabel3;
|
||||
private javax.swing.JLabel jLabel4;
|
||||
private javax.swing.JLabel jLabel5;
|
||||
private javax.swing.JLabel jLabel7;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel jPanel2;
|
||||
private ch.psi.pshell.plot.LinePlotJFree plot;
|
||||
private javax.swing.JSpinner spinnerLatency;
|
||||
private javax.swing.JSpinner spinnerPhaseRef;
|
||||
private javax.swing.JSpinner spinnerSamples;
|
||||
private javax.swing.JSpinner spinnerStart;
|
||||
private javax.swing.JSpinner spinnerStep;
|
||||
private javax.swing.JSpinner spinnerStop;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
||||
Reference in New Issue
Block a user