Files
x11ma/plugins/XPEEM_Settings.java
2023-01-26 16:11:57 +01:00

298 lines
14 KiB
Java

import ch.psi.pshell.core.CommandSource;
import ch.psi.pshell.core.Context;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.State;
import ch.psi.utils.swing.SwingUtils;
import java.awt.Component;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
/**
*
*/
public class XPEEM_Settings extends Panel {
public XPEEM_Settings() {
initComponents();
}
//Overridable callbacks
@Override
public void onInitialize(int runCount) {
}
@Override
public void onStateChange(State state, State former) {
for (Component c : SwingUtils.getComponentsByType(this, JButton.class)){
c.setEnabled(state==State.Ready);
}
}
@Override
public void onExecutedFile(String fileName, Object result) {
}
@Override
protected void onTimer() {
}
@Override
protected void onLoaded() {
}
@Override
protected void onUnloaded() {
}
//Invoked by 'update()' to update components in the event thread
@Override
protected void doUpdate() {
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
ButtonDefaultXrays = new javax.swing.JButton();
ButtonDefaultOptics15kV = new javax.swing.JButton();
ButtonDefaultOptics10kV = new javax.swing.JButton();
ButtonNeutralizePosition = new javax.swing.JButton();
label1 = new java.awt.Label();
label2 = new java.awt.Label();
label3 = new java.awt.Label();
label4 = new java.awt.Label();
label5 = new java.awt.Label();
label6 = new java.awt.Label();
label7 = new java.awt.Label();
buttonRunSelected = new javax.swing.JButton();
ButtonDefaultXrays.setText("X-rays (Standard)");
ButtonDefaultXrays.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButtonDefaultXraysActionPerformed(evt);
}
});
ButtonDefaultOptics15kV.setText("PEEM Optics 15 kV (Standard)");
ButtonDefaultOptics15kV.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButtonDefaultOptics15kVActionPerformed(evt);
}
});
ButtonDefaultOptics10kV.setText("PEEM Optics 10 kV (Standard)");
ButtonDefaultOptics10kV.setToolTipText("");
ButtonDefaultOptics10kV.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButtonDefaultOptics10kVActionPerformed(evt);
}
});
ButtonNeutralizePosition.setText("Sample Position (Neutralize)");
ButtonNeutralizePosition.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButtonNeutralizePositionActionPerformed(evt);
}
});
label1.setText("ID2 only, lin. hor., harm.=1, offset = -2.0, G3, 800 eV,");
label2.setText("diff. order = 1, cff = 2.25, energy slit = 300, FE = closed, ");
label3.setText("Obj. = 1220.0 mA, Stig. A,B = 0.0, Obj. Align. x,y = 0.0, Start voltage = 0.0,");
label4.setText("Obj. = 1475.0 mA, Stig. A,B = 0.0, Obj. Align. x,y = 0.0, Start voltage = 0.0,");
label5.setText(" FOV = 100 um, CA = open, Slit = open.");
label6.setText(" FOV = 100 um, CA = open, Slit = open.");
label7.setText("x,y = 0.0, tilt = 0.0");
buttonRunSelected.setText("Run Selected");
buttonRunSelected.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonRunSelectedActionPerformed(evt);
}
});
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(79, 79, 79)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(ButtonDefaultOptics10kV)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, 340, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(ButtonDefaultOptics15kV)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, 481, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(ButtonDefaultXrays)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(buttonRunSelected, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(ButtonNeutralizePosition, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(68, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {ButtonDefaultOptics10kV, ButtonDefaultOptics15kV, ButtonDefaultXrays, ButtonNeutralizePosition});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(46, 46, 46)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(ButtonDefaultOptics15kV)
.addGroup(layout.createSequentialGroup()
.addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(39, 39, 39)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(ButtonDefaultOptics10kV)
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(ButtonDefaultXrays)
.addGap(42, 42, 42)
.addComponent(ButtonNeutralizePosition))
.addGroup(layout.createSequentialGroup()
.addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(label2, 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)
.addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()
.addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(1, 1, 1)
.addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
.addComponent(buttonRunSelected)
.addGap(16, 16, 16))
);
label1.getAccessibleContext().setAccessibleName("ID2 only, lin. hor., G3, 800 eV, energy slit = 300,");
}// </editor-fold>//GEN-END:initComponents
private void ButtonDefaultXraysActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonDefaultXraysActionPerformed
try {
evalAsync("xrays_default()").handle((ret,ex)->{
if (ex!=null){
showException((Exception)ex);
}
return ret;
});
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_ButtonDefaultXraysActionPerformed
private void ButtonDefaultOptics15kVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonDefaultOptics15kVActionPerformed
try {
evalAsync("peem_optics_default_15kV()").handle((ret,ex)->{
if (ex!=null){
showException((Exception)ex);
}
return ret;
});
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_ButtonDefaultOptics15kVActionPerformed
private void ButtonDefaultOptics10kVActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonDefaultOptics10kVActionPerformed
try {
evalAsync("peem_optics_default_10kV()").handle((ret,ex)->{
if (ex!=null){
showException((Exception)ex);
}
return ret;
});
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_ButtonDefaultOptics10kVActionPerformed
private void ButtonNeutralizePositionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonNeutralizePositionActionPerformed
try {
evalAsync("neutralize_position()").handle((ret,ex)->{
if (ex!=null){
showException((Exception)ex);
}
return ret;
});
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_ButtonNeutralizePositionActionPerformed
private void buttonRunSelectedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonRunSelectedActionPerformed
try {
getContext().startExecution(CommandSource.plugin, null, null,null, false);
new Thread(()->{
try{
if (true){
this.eval("peem_optics_default_15kV()", true);
}
if (true){
this.eval("peem_optics_default_10kV()", true);
}
if (true){
this.eval("xrays_default()", true);
}
if (true){
this.eval("neutralize_position()", true);
}
} catch (Exception ex){
getLogger().log(Level.WARNING, null, ex);
} finally{
try {
getContext().endExecution();
} catch (Context.ContextStateException ex) {
getLogger().log(Level.SEVERE, null, ex);
}
}
}).start();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonRunSelectedActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton ButtonDefaultOptics10kV;
private javax.swing.JButton ButtonDefaultOptics15kV;
private javax.swing.JButton ButtonDefaultXrays;
private javax.swing.JButton ButtonNeutralizePosition;
private javax.swing.JButton buttonRunSelected;
private java.awt.Label label1;
private java.awt.Label label2;
private java.awt.Label label3;
private java.awt.Label label4;
private java.awt.Label label5;
private java.awt.Label label6;
private java.awt.Label label7;
// End of variables declaration//GEN-END:variables
}