294 lines
14 KiB
Java
294 lines
14 KiB
Java
/*
|
|
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
|
|
*/
|
|
|
|
import ch.psi.pshell.plot.Plot;
|
|
import ch.psi.pshell.ui.App;
|
|
import ch.psi.pshell.ui.Panel;
|
|
import ch.psi.utils.State;
|
|
import java.awt.Component;
|
|
import java.util.HashMap;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public class Correlation extends Panel {
|
|
|
|
public Correlation() {
|
|
initComponents();
|
|
this.setPersistedComponents(new Component[]{textDevX, textDevY, spinnerInterval, spinnerWindow, checkBS});
|
|
plot.getAxis(Plot.AxisId.X).setLabel(null);
|
|
plot.getAxis(Plot.AxisId.Y).setLabel(null);
|
|
}
|
|
|
|
//Overridable callbacks
|
|
@Override
|
|
public void onInitialize(int runCount) {
|
|
super.onInitialize(runCount);
|
|
this.startTimer(100, 10);
|
|
if (App.hasArgument("dx")) {
|
|
textDevX.setText(App.getArgumentValue("dx"));
|
|
}
|
|
if (App.hasArgument("dy")) {
|
|
textDevY.setText(App.getArgumentValue("dy"));
|
|
}
|
|
try{
|
|
if (App.hasArgument("bs")) {
|
|
checkBS.setSelected(Boolean.valueOf(App.getArgumentValue("bs")));
|
|
}
|
|
} catch (Exception ex){
|
|
System.err.println(ex.getMessage());
|
|
}
|
|
try{
|
|
if (App.hasArgument("interval")) {
|
|
spinnerInterval.setValue(Double.valueOf(App.getArgumentValue("interval")));
|
|
}
|
|
} catch (Exception ex){
|
|
System.err.println(ex.getMessage());
|
|
}
|
|
try{
|
|
if (App.hasArgument("window")) {
|
|
spinnerWindow.setValue(Integer.valueOf(App.getArgumentValue("window")));
|
|
}
|
|
} catch (Exception ex){
|
|
System.err.println(ex.getMessage());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onTimer(){
|
|
String correlation="";
|
|
try{
|
|
correlation = String.format("%1.4f", Double.valueOf((Double)getController().getInterpreterVariable("corr")));
|
|
} catch (Exception ex){
|
|
correlation = "";
|
|
}
|
|
|
|
textCorrelation.setText(correlation);
|
|
}
|
|
|
|
@Override
|
|
public void onStateChange(State state, State former) {
|
|
buttonStart.setEnabled(state==State.Ready);
|
|
buttonStop.setEnabled(state==State.Busy);
|
|
textDevX.setEnabled(state==State.Ready);
|
|
textDevY.setEnabled(state==State.Ready);
|
|
spinnerInterval.setEnabled(state==State.Ready);
|
|
spinnerWindow.setEnabled(state==State.Ready);
|
|
|
|
if ((former==State.Initializing) && (state == State.Ready)){
|
|
if (App.hasArgument("start")) {
|
|
buttonStartActionPerformed(null);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onExecutedFile(String fileName, Object result) {
|
|
}
|
|
|
|
|
|
//Callback to perform update - in event thread
|
|
@Override
|
|
protected void doUpdate() {
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
private void initComponents() {
|
|
|
|
plot = new ch.psi.pshell.plot.LinePlotJFree();
|
|
jPanel1 = new javax.swing.JPanel();
|
|
jLabel1 = new javax.swing.JLabel();
|
|
textDevX = new javax.swing.JTextField();
|
|
textDevY = new javax.swing.JTextField();
|
|
jLabel2 = new javax.swing.JLabel();
|
|
jLabel3 = new javax.swing.JLabel();
|
|
spinnerInterval = new javax.swing.JSpinner();
|
|
jLabel4 = new javax.swing.JLabel();
|
|
spinnerWindow = new javax.swing.JSpinner();
|
|
buttonStart = new javax.swing.JButton();
|
|
buttonStop = new javax.swing.JButton();
|
|
jLabel5 = new javax.swing.JLabel();
|
|
textCorrelation = new javax.swing.JTextField();
|
|
checkBS = new javax.swing.JCheckBox();
|
|
|
|
plot.setTitle("");
|
|
|
|
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
|
jLabel1.setText("X device:");
|
|
|
|
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
|
jLabel2.setText("Y device:");
|
|
|
|
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
|
jLabel3.setText("Interval (s):");
|
|
|
|
spinnerInterval.setModel(new javax.swing.SpinnerNumberModel(Double.valueOf(0.1d), Double.valueOf(0.001d), null, Double.valueOf(1.0d)));
|
|
|
|
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
|
|
jLabel4.setText("Window size:");
|
|
|
|
spinnerWindow.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(50), Integer.valueOf(3), null, Integer.valueOf(1)));
|
|
|
|
buttonStart.setText("Start");
|
|
buttonStart.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonStartActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
buttonStop.setText("Stop");
|
|
buttonStop.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonStopActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
|
jLabel5.setText("Correlation:");
|
|
|
|
textCorrelation.setEditable(false);
|
|
textCorrelation.setHorizontalAlignment(javax.swing.JTextField.CENTER);
|
|
|
|
checkBS.setText("Beam Synchronous");
|
|
|
|
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()
|
|
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(jLabel1)
|
|
.addComponent(jLabel2)
|
|
.addComponent(jLabel3)
|
|
.addComponent(jLabel4))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(textDevX, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(textDevY, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(spinnerInterval, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(spinnerWindow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(checkBS)))
|
|
.addGroup(jPanel1Layout.createSequentialGroup()
|
|
.addGap(0, 0, Short.MAX_VALUE)
|
|
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
|
.addComponent(textCorrelation)
|
|
.addComponent(buttonStart, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addComponent(buttonStop, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
|
|
.addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
|
|
);
|
|
|
|
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3, jLabel4});
|
|
|
|
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerInterval, spinnerWindow});
|
|
|
|
jPanel1Layout.setVerticalGroup(
|
|
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel1Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(jLabel1)
|
|
.addComponent(textDevX, 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(textDevY, 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(spinnerInterval, 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(spinnerWindow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
|
.addComponent(checkBS)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
|
|
.addComponent(jLabel5)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(textCorrelation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
|
|
.addComponent(buttonStart)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(buttonStop)
|
|
.addGap(41, 41, 41))
|
|
);
|
|
|
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
|
this.setLayout(layout);
|
|
layout.setHorizontalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
|
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
|
|
.addContainerGap())
|
|
);
|
|
layout.setVerticalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addComponent(plot, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addContainerGap())))
|
|
);
|
|
}// </editor-fold>//GEN-END:initComponents
|
|
|
|
private void buttonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStopActionPerformed
|
|
try {
|
|
abort();
|
|
} catch (InterruptedException ex) {
|
|
showException(ex);
|
|
}
|
|
}//GEN-LAST:event_buttonStopActionPerformed
|
|
|
|
private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed
|
|
try {
|
|
HashMap args = new HashMap();
|
|
args.put("dx", textDevX.getText());
|
|
args.put("dy", textDevY.getText());
|
|
args.put("interval", spinnerInterval.getValue());
|
|
args.put("window", spinnerWindow.getValue());
|
|
args.put("bs", checkBS.isSelected());
|
|
|
|
args.put("p", plot);
|
|
runAsync("Correlation/Correlation", args).handle((ok, ex) -> {
|
|
if (ex != null) {
|
|
ex.printStackTrace();
|
|
}
|
|
return ok;
|
|
});
|
|
|
|
} catch (Exception ex) {
|
|
showException(ex);
|
|
}
|
|
}//GEN-LAST:event_buttonStartActionPerformed
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
private javax.swing.JButton buttonStart;
|
|
private javax.swing.JButton buttonStop;
|
|
private javax.swing.JCheckBox checkBS;
|
|
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.JPanel jPanel1;
|
|
private ch.psi.pshell.plot.LinePlotJFree plot;
|
|
private javax.swing.JSpinner spinnerInterval;
|
|
private javax.swing.JSpinner spinnerWindow;
|
|
private javax.swing.JTextField textCorrelation;
|
|
private javax.swing.JTextField textDevX;
|
|
private javax.swing.JTextField textDevY;
|
|
// End of variables declaration//GEN-END:variables
|
|
}
|