diff --git a/plugins/Commands.form b/plugins/Commands.form index ff9cfab..4e35b90 100644 --- a/plugins/Commands.form +++ b/plugins/Commands.form @@ -16,13 +16,67 @@ - + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/Commands.java b/plugins/Commands.java index 15d5a86..08160e1 100644 --- a/plugins/Commands.java +++ b/plugins/Commands.java @@ -2,8 +2,15 @@ * 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; /** * @@ -22,7 +29,9 @@ public class Commands extends Panel { @Override public void onStateChange(State state, State former) { - + for (Component c : SwingUtils.getComponentsByType(this, Component.class)){ + c.setEnabled(state == State.Ready); + } } @Override @@ -39,18 +48,96 @@ public class Commands extends Panel { // //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) - .addGap(0, 449, Short.MAX_VALUE) + .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) - .addGap(0, 137, Short.MAX_VALUE) + .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)) ); }// //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 }