404 lines
20 KiB
Java
404 lines
20 KiB
Java
/*
|
|
* Copyright (c) 2014-2017 Paul Scherrer Institute. All rights reserved.
|
|
*/
|
|
|
|
import ch.psi.pshell.core.Context;
|
|
import ch.psi.pshell.ui.Panel;
|
|
import ch.psi.utils.State;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import javax.swing.JSpinner;
|
|
import javax.swing.JTextField;
|
|
import javax.swing.SwingConstants;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public class Expert extends Panel {
|
|
|
|
public Expert() {
|
|
initComponents();
|
|
((JSpinner.DefaultEditor)spinnerSegment.getEditor()).getTextField().setHorizontalAlignment(JTextField.RIGHT);
|
|
}
|
|
|
|
//Overridable callbacks
|
|
@Override
|
|
public void onInitialize(int runCount) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onStateChange(State state, State former) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onExecutedFile(String fileName, Object result) {
|
|
}
|
|
|
|
//Callback to perform update - in event thread
|
|
@Override
|
|
protected void doUpdate() {
|
|
}
|
|
|
|
void execute(String statement){
|
|
execute(statement, false);
|
|
}
|
|
|
|
void execute(String statement, boolean background){
|
|
try {
|
|
evalAsync(statement, background).handle((ret, ex) -> {
|
|
if (ex != null){
|
|
showException((Exception)ex);
|
|
}
|
|
return ret;
|
|
});
|
|
} catch (Exception ex) {
|
|
showException(ex);
|
|
}
|
|
}
|
|
|
|
void execute(String script, Object args){
|
|
try {
|
|
runAsync(script, args).handle((ret, ex) -> {
|
|
if (ex != null){
|
|
showException((Exception)ex);
|
|
}
|
|
return ret;
|
|
});
|
|
} catch (Exception ex) {
|
|
showException(ex);
|
|
}
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
|
private void initComponents() {
|
|
|
|
jPanel1 = new javax.swing.JPanel();
|
|
buttonEnable = new javax.swing.JButton();
|
|
buttonDisable = new javax.swing.JButton();
|
|
jPanel2 = new javax.swing.JPanel();
|
|
buttonHomingHexiposi = new javax.swing.JButton();
|
|
buttonPositionsHexiposi = new javax.swing.JButton();
|
|
jPanel3 = new javax.swing.JPanel();
|
|
buttonReleasePsys = new javax.swing.JButton();
|
|
buttonEnableAll = new javax.swing.JButton();
|
|
buttonReleaseLocal = new javax.swing.JButton();
|
|
jPanel4 = new javax.swing.JPanel();
|
|
spinnerSample = new javax.swing.JSpinner();
|
|
checkForce = new javax.swing.JCheckBox();
|
|
buttonMount = new javax.swing.JButton();
|
|
jLabel1 = new javax.swing.JLabel();
|
|
spinnerSegment = new javax.swing.JSpinner();
|
|
jLabel2 = new javax.swing.JLabel();
|
|
spinnerPuck = new javax.swing.JSpinner();
|
|
jLabel3 = new javax.swing.JLabel();
|
|
buttonUnmount = new javax.swing.JButton();
|
|
|
|
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Robot"));
|
|
|
|
buttonEnable.setText("Enable");
|
|
buttonEnable.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonEnableActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
buttonDisable.setText("Disable");
|
|
buttonDisable.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonDisableActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
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(78, Short.MAX_VALUE)
|
|
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(buttonEnable)
|
|
.addComponent(buttonDisable))
|
|
.addContainerGap(79, Short.MAX_VALUE))
|
|
);
|
|
|
|
jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonDisable, buttonEnable});
|
|
|
|
jPanel1Layout.setVerticalGroup(
|
|
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel1Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addComponent(buttonEnable)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(buttonDisable)
|
|
.addContainerGap())
|
|
);
|
|
|
|
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Hexiposi"));
|
|
|
|
buttonHomingHexiposi.setText("Homing");
|
|
buttonHomingHexiposi.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonHomingHexiposiActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
buttonPositionsHexiposi.setText("Positions");
|
|
buttonPositionsHexiposi.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonPositionsHexiposiActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
|
jPanel2.setLayout(jPanel2Layout);
|
|
jPanel2Layout.setHorizontalGroup(
|
|
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
|
|
.addContainerGap(75, Short.MAX_VALUE)
|
|
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(buttonHomingHexiposi)
|
|
.addComponent(buttonPositionsHexiposi))
|
|
.addContainerGap(75, Short.MAX_VALUE))
|
|
);
|
|
|
|
jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonHomingHexiposi, buttonPositionsHexiposi});
|
|
|
|
jPanel2Layout.setVerticalGroup(
|
|
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel2Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addComponent(buttonHomingHexiposi)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(buttonPositionsHexiposi)
|
|
.addContainerGap())
|
|
);
|
|
|
|
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Safety"));
|
|
|
|
buttonReleasePsys.setText("Release PSYS");
|
|
buttonReleasePsys.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonReleasePsysActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
buttonEnableAll.setText("Enable All");
|
|
buttonEnableAll.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonEnableAllActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
buttonReleaseLocal.setText("Release Local");
|
|
buttonReleaseLocal.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonReleaseLocalActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
|
|
jPanel3.setLayout(jPanel3Layout);
|
|
jPanel3Layout.setHorizontalGroup(
|
|
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel3Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
|
.addComponent(buttonEnableAll, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addGroup(jPanel3Layout.createSequentialGroup()
|
|
.addComponent(buttonReleasePsys)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
|
.addComponent(buttonReleaseLocal)))
|
|
.addContainerGap())
|
|
);
|
|
jPanel3Layout.setVerticalGroup(
|
|
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel3Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addComponent(buttonEnableAll)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
|
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(buttonReleaseLocal)
|
|
.addComponent(buttonReleasePsys))
|
|
.addContainerGap())
|
|
);
|
|
|
|
jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Commands"));
|
|
|
|
spinnerSample.setModel(new javax.swing.SpinnerNumberModel(1, 1, 16, 1));
|
|
|
|
checkForce.setText("Force");
|
|
|
|
buttonMount.setText("Mount");
|
|
buttonMount.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonMountActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
jLabel1.setText("Segment:");
|
|
|
|
spinnerSegment.setModel(new javax.swing.SpinnerListModel(new String[] {"A", "B", "C", "D", "E", "F"}));
|
|
|
|
jLabel2.setText("Puck:");
|
|
|
|
spinnerPuck.setModel(new javax.swing.SpinnerNumberModel(1, 1, 5, 1));
|
|
|
|
jLabel3.setText("Sample:");
|
|
|
|
buttonUnmount.setText("Unmount");
|
|
buttonUnmount.addActionListener(new java.awt.event.ActionListener() {
|
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
|
buttonUnmountActionPerformed(evt);
|
|
}
|
|
});
|
|
|
|
javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
|
|
jPanel4.setLayout(jPanel4Layout);
|
|
jPanel4Layout.setHorizontalGroup(
|
|
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel4Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(buttonMount, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(buttonUnmount, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(checkForce))
|
|
.addGap(18, 18, 18)
|
|
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(jLabel3)
|
|
.addComponent(jLabel2)
|
|
.addComponent(jLabel1))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(spinnerSample, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(spinnerPuck, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(spinnerSegment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addContainerGap(13, Short.MAX_VALUE))
|
|
);
|
|
|
|
jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3});
|
|
|
|
jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {spinnerPuck, spinnerSample, spinnerSegment});
|
|
|
|
jPanel4Layout.setVerticalGroup(
|
|
jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(jPanel4Layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(buttonMount)
|
|
.addComponent(jLabel1)
|
|
.addComponent(spinnerSegment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(jLabel2)
|
|
.addComponent(spinnerPuck, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(buttonUnmount))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(jLabel3)
|
|
.addComponent(spinnerSample, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(checkForce))
|
|
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 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()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
|
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGap(6, 6, 6)
|
|
.addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
);
|
|
layout.setVerticalGroup(
|
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
|
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
|
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
|
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
|
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
|
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
|
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
|
);
|
|
}// </editor-fold>//GEN-END:initComponents
|
|
|
|
private void buttonEnableAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEnableAllActionPerformed
|
|
execute("enable_power()");
|
|
}//GEN-LAST:event_buttonEnableAllActionPerformed
|
|
|
|
private void buttonMountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonMountActionPerformed
|
|
String segment = (String) spinnerSegment.getValue();
|
|
int puck = (Integer) spinnerPuck.getValue();
|
|
int sample = (Integer) spinnerSample.getValue();
|
|
String force = checkForce.isSelected() ? "True" : "False";
|
|
execute("mount('" + segment + "'," + puck + "," + sample + ", force=" + force + ")");
|
|
|
|
}//GEN-LAST:event_buttonMountActionPerformed
|
|
|
|
private void buttonEnableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonEnableActionPerformed
|
|
execute("robot.enable()");
|
|
}//GEN-LAST:event_buttonEnableActionPerformed
|
|
|
|
private void buttonDisableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDisableActionPerformed
|
|
execute("robot.disable()");
|
|
}//GEN-LAST:event_buttonDisableActionPerformed
|
|
|
|
private void buttonReleaseLocalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReleaseLocalActionPerformed
|
|
execute("release_local()");
|
|
}//GEN-LAST:event_buttonReleaseLocalActionPerformed
|
|
|
|
private void buttonReleasePsysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReleasePsysActionPerformed
|
|
execute("release_psys()");
|
|
}//GEN-LAST:event_buttonReleasePsysActionPerformed
|
|
|
|
private void buttonHomingHexiposiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonHomingHexiposiActionPerformed
|
|
execute("hexiposi.move_home()");
|
|
}//GEN-LAST:event_buttonHomingHexiposiActionPerformed
|
|
|
|
private void buttonPositionsHexiposiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPositionsHexiposiActionPerformed
|
|
this.showDevicePanel("hexiposi");
|
|
}//GEN-LAST:event_buttonPositionsHexiposiActionPerformed
|
|
|
|
private void buttonUnmountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUnmountActionPerformed
|
|
String segment = (String) spinnerSegment.getValue();
|
|
int puck = (Integer) spinnerPuck.getValue();
|
|
int sample = (Integer) spinnerSample.getValue();
|
|
String force = checkForce.isSelected() ? "True" : "False";
|
|
execute("unmount('" + segment + "'," + puck + "," + sample + ", force=" + force + ")");
|
|
}//GEN-LAST:event_buttonUnmountActionPerformed
|
|
|
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
private javax.swing.JButton buttonDisable;
|
|
private javax.swing.JButton buttonEnable;
|
|
private javax.swing.JButton buttonEnableAll;
|
|
private javax.swing.JButton buttonHomingHexiposi;
|
|
private javax.swing.JButton buttonMount;
|
|
private javax.swing.JButton buttonPositionsHexiposi;
|
|
private javax.swing.JButton buttonReleaseLocal;
|
|
private javax.swing.JButton buttonReleasePsys;
|
|
private javax.swing.JButton buttonUnmount;
|
|
private javax.swing.JCheckBox checkForce;
|
|
private javax.swing.JLabel jLabel1;
|
|
private javax.swing.JLabel jLabel2;
|
|
private javax.swing.JLabel jLabel3;
|
|
private javax.swing.JPanel jPanel1;
|
|
private javax.swing.JPanel jPanel2;
|
|
private javax.swing.JPanel jPanel3;
|
|
private javax.swing.JPanel jPanel4;
|
|
private javax.swing.JSpinner spinnerPuck;
|
|
private javax.swing.JSpinner spinnerSample;
|
|
private javax.swing.JSpinner spinnerSegment;
|
|
// End of variables declaration//GEN-END:variables
|
|
}
|