Files
x06da/plugins/Commands.java
2016-04-20 12:17:12 +02:00

144 lines
5.4 KiB
Java

/*
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
*/
import ch.psi.pshell.core.Controller;
import ch.psi.pshell.ui.Panel;
import ch.psi.utils.swing.SwingUtils;
import ch.psi.utils.State;
import java.awt.Component;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptException;
/**
*
*/
public class Commands extends Panel {
public Commands() {
initComponents();
}
//Overridable callbacks
@Override
public void onInitialize(int runCount) {
}
@Override
public void onStateChange(State state, State former) {
for (Component c : SwingUtils.getComponentsByType(this, Component.class)){
c.setEnabled(state == State.Ready);
}
}
@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() {
btRock = new javax.swing.JButton();
btFbm = new javax.swing.JButton();
btSete = new javax.swing.JButton();
spEnergy = new javax.swing.JSpinner();
btRock.setText("Rock");
btRock.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btRockActionPerformed(evt);
}
});
btFbm.setText("Feedback Mirror");
btFbm.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btFbmActionPerformed(evt);
}
});
btSete.setText("Set Energy");
btSete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btSeteActionPerformed(evt);
}
});
spEnergy.setModel(new javax.swing.SpinnerNumberModel(6.0d, 4.7d, 17.5d, 0.1d));
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(96, 96, 96)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btFbm, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btRock, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btSete, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addComponent(spEnergy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(133, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btFbm, btRock});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(56, 56, 56)
.addComponent(btRock)
.addGap(18, 18, 18)
.addComponent(btFbm)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btSete)
.addComponent(spEnergy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(210, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void btRockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRockActionPerformed
try {
getController().evalLineAsync("rock()");
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_btRockActionPerformed
private void btFbmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFbmActionPerformed
try {
getController().evalLineAsync("fbm()");
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_btFbmActionPerformed
private void btSeteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSeteActionPerformed
try {
getController().evalLineAsync("sete(" + String.valueOf(spEnergy.getValue()) + ")");
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_btSeteActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btFbm;
private javax.swing.JButton btRock;
private javax.swing.JButton btSete;
private javax.swing.JSpinner spEnergy;
// End of variables declaration//GEN-END:variables
}