Files
dev/plugins/PanelPlugin.java
2021-04-28 09:29:19 +02:00

186 lines
9.2 KiB
Java
Executable File

/*
* Copyright (c) 2014 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.awt.Component;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
/**
*
*/
public class PanelPlugin extends Panel {
public PanelPlugin() {
initComponents();
this.setPersistedComponents(new Component[]{jRadioButton1, jRadioButton2});
}
//Overridables
@Override
public void onInitialize(int runCount) {
}
@Override
public void onStateChange(State state, State former) {
}
@Override
public void onExecutedFile(String fileName, Object result) {
}
@Override
public void setEnabled(boolean value) {
super.setEnabled(value);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
motorPanel2 = new ch.psi.pshell.swing.MotorPanel();
scriptButton1 = new ch.psi.pshell.swing.ScriptButton();
scriptButton2 = new ch.psi.pshell.swing.ScriptButton();
jSpinner1 = new javax.swing.JSpinner();
jSpinner2 = new javax.swing.JSpinner();
jSpinner3 = new javax.swing.JSpinner();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
buttonExecShellCmd = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
motorPanel2.setDeviceName("m1");
scriptButton1.setScript("Test1");
scriptButton2.setArguments(new String[] {"start", "end", "step"});
scriptButton2.setScript("Test11");
scriptButton2.setText("Start Args");
jSpinner1.setModel(new javax.swing.SpinnerNumberModel(1.0d, 0.0d, 10.0d, 1.0d));
jSpinner1.setName("start"); // NOI18N
jSpinner2.setModel(new javax.swing.SpinnerNumberModel(10.0d, 0.0d, 10.0d, 1.0d));
jSpinner2.setName("end"); // NOI18N
jSpinner3.setModel(new javax.swing.SpinnerNumberModel(1.0d, 0.0d, 10.0d, 1.0d));
jSpinner3.setName("step"); // NOI18N
buttonGroup1.add(jRadioButton1);
jRadioButton1.setSelected(true);
jRadioButton1.setText("jRadioButton1");
buttonGroup1.add(jRadioButton2);
jRadioButton2.setText("jRadioButton2");
buttonExecShellCmd.setText("Exec Async");
buttonExecShellCmd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonExecShellCmdActionPerformed(evt);
}
});
jButton2.setText("Exec Sync");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scriptButton2, 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)
.addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(motorPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(scriptButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton2)
.addComponent(jRadioButton1))))
.addContainerGap(168, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2)
.addComponent(buttonExecShellCmd))
.addGap(225, 225, 225))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scriptButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(motorPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(scriptButton2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSpinner2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jRadioButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton2)
.addGap(18, 18, 18)
.addComponent(buttonExecShellCmd)
.addGap(18, 18, 18)
.addComponent(jButton2)
.addContainerGap(35, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void buttonExecShellCmdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExecShellCmdActionPerformed
try {
String shellCommand="sleep 5; uname";
boolean background = false;
evalAsync("exec_cmd('" + shellCommand + "')", background).handle((ret,ex)->{
((JButton)evt.getSource()).setEnabled(true);
if (ex!=null){
showException((Exception)ex);
} else {
getContext().scriptingLog(String.format("Shell command '%s' return value: %s", shellCommand, String.valueOf(ret)));
}
return ret;
});
((JButton)evt.getSource()).setEnabled(false);
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_buttonExecShellCmdActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton buttonExecShellCmd;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton jButton2;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JSpinner jSpinner1;
private javax.swing.JSpinner jSpinner2;
private javax.swing.JSpinner jSpinner3;
private ch.psi.pshell.swing.MotorPanel motorPanel2;
private ch.psi.pshell.swing.ScriptButton scriptButton1;
private ch.psi.pshell.swing.ScriptButton scriptButton2;
// End of variables declaration//GEN-END:variables
}