271 lines
15 KiB
Java
Executable File
271 lines
15 KiB
Java
Executable File
/*
|
|
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
|
|
*/
|
|
|
|
import ch.psi.pshell.core.Context;
|
|
import ch.psi.pshell.epics.ChannelDouble;
|
|
import ch.psi.pshell.epics.GenericChannel;
|
|
import ch.psi.pshell.plot.Plot;
|
|
import ch.psi.pshell.swing.DevicePanel;
|
|
import ch.psi.pshell.ui.Panel;
|
|
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.swing.JButton;
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public class PanelPlugin extends Panel {
|
|
|
|
public PanelPlugin() {
|
|
initComponents();
|
|
this.setPersistedComponents(new Component[]{jRadioButton1, jRadioButton2});
|
|
line.getAxis(Plot.AxisId.Y).setLabel("LinePlot");
|
|
time.getAxis(Plot.AxisId.Y).setLabel("TimePlot");
|
|
time.setTitle("Test");
|
|
|
|
}
|
|
|
|
//Overridables
|
|
|
|
@Override
|
|
public void onInitialize(int runCount) {
|
|
DevicePanel[] panels = new DevicePanel[]{panelSetp, panelRbck};
|
|
for (DevicePanel p : panels){
|
|
GenericChannel channel = new GenericChannel(p.getName(), p.getName(), 3);
|
|
channel.setMonitored(true);
|
|
try {
|
|
channel.initialize();
|
|
p.setDevice(channel);
|
|
} catch (Exception ex) {
|
|
Logger.getLogger(PanelPlugin.class.getName()).log(Level.SEVERE, null, ex);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@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();
|
|
line = new ch.psi.pshell.plot.LinePlotJFree();
|
|
time = new ch.psi.pshell.plot.TimePlotJFree();
|
|
panelSetp = new ch.psi.pshell.swing.RegisterPanel();
|
|
panelRbck = new ch.psi.pshell.swing.DeviceValuePanel();
|
|
try {
|
|
dvc = new ch.psi.pshell.swing.DeviceValueChart();
|
|
} catch (java.lang.ClassNotFoundException e1) {
|
|
e1.printStackTrace();
|
|
} catch (java.lang.InstantiationException e2) {
|
|
e2.printStackTrace();
|
|
} catch (java.lang.IllegalAccessException e3) {
|
|
e3.printStackTrace();
|
|
}
|
|
pvp = new ch.psi.pshell.swing.ProcessVariablePanel();
|
|
|
|
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");
|
|
|
|
panelSetp.setName("TESTIOC:TESTCALCOUT:Input"); // NOI18N
|
|
|
|
panelRbck.setName("TESTIOC:TESTCALCOUT:Input"); // NOI18N
|
|
|
|
dvc.setDeviceName("sin");
|
|
|
|
pvp.setDeviceName("motor");
|
|
pvp.setShowStop(false);
|
|
|
|
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.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)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
|
.addComponent(buttonExecShellCmd)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(jRadioButton2)
|
|
.addComponent(jRadioButton1)))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(jButton2)
|
|
.addGap(219, 219, 219)
|
|
.addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
|
|
.addGap(6, 6, 6)
|
|
.addComponent(pvp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addComponent(line, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addGap(6, 6, 6)
|
|
.addComponent(time, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addGap(86, 86, 86)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addComponent(panelSetp, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(panelRbck, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addComponent(scriptButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.addComponent(dvc, javax.swing.GroupLayout.PREFERRED_SIZE, 342, 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()
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addContainerGap()
|
|
.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)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(jSpinner3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addGap(21, 21, 21)
|
|
.addComponent(jRadioButton1)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(jRadioButton2)
|
|
.addGap(18, 18, 18)
|
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
|
.addComponent(buttonExecShellCmd)
|
|
.addComponent(jButton2))))
|
|
.addGap(18, 18, 18)
|
|
.addComponent(pvp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGroup(layout.createSequentialGroup()
|
|
.addComponent(line, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
|
.addComponent(time, 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(dvc, 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(panelSetp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addComponent(panelRbck, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
.addGap(44, 44, 44)
|
|
.addComponent(scriptButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
|
.addGap(25, 25, 25))
|
|
);
|
|
|
|
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {panelRbck, panelSetp});
|
|
|
|
}// </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 ch.psi.pshell.swing.DeviceValueChart dvc;
|
|
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.plot.LinePlotJFree line;
|
|
private ch.psi.pshell.swing.MotorPanel motorPanel2;
|
|
private ch.psi.pshell.swing.DeviceValuePanel panelRbck;
|
|
private ch.psi.pshell.swing.RegisterPanel panelSetp;
|
|
private ch.psi.pshell.swing.ProcessVariablePanel pvp;
|
|
private ch.psi.pshell.swing.ScriptButton scriptButton1;
|
|
private ch.psi.pshell.swing.ScriptButton scriptButton2;
|
|
private ch.psi.pshell.plot.TimePlotJFree time;
|
|
// End of variables declaration//GEN-END:variables
|
|
}
|