Closedown

This commit is contained in:
x07maop
2015-08-24 09:23:31 +02:00
parent d3a33f151a
commit b8c8cf77a7
4 changed files with 113 additions and 60 deletions
+1
View File
@@ -577,6 +577,7 @@
<Component class="javax.swing.JButton" name="buttonAbort">
<Properties>
<Property name="text" type="java.lang.String" value="Abort"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonAbortActionPerformed"/>
+50 -40
View File
@@ -33,18 +33,18 @@ import ch.psi.pshell.ui.Panel;
*
*/
public class EnergyScan extends Panel {
public EnergyScan() {
initComponents();
buttonDefaultsActionPerformed(null);
}
ChannelDoubleArray data;
ChannelDoubleArray edata;
ChannelDoubleArray idata;
ChannelDoubleArray fdata;
ChannelInteger count;
double[] offsets = new double[4];
//Overridable callbacks
@@ -53,22 +53,22 @@ public class EnergyScan extends Panel {
super.onStart();
loadConfig();
}
@Override
public void onInitialize(int runCount) {
super.onInitialize(runCount);
count = (ChannelInteger) getController().getDevicePool().getByName("count");
data = (ChannelDoubleArray) getController().getDevicePool().getByName("data");
edata = (ChannelDoubleArray) getController().getDevicePool().getByName("edata");
idata = (ChannelDoubleArray) getController().getDevicePool().getByName("idata");
fdata = (ChannelDoubleArray) getController().getDevicePool().getByName("fdata");
getController().getDevicePool().getByName("count").addListener(new DeviceListener() {
@Override
public void onStateChanged(Device device, State state, State former) {
}
@Override
public void onValueChanged(Device device, Object value, Object former) {
update();
@@ -77,14 +77,14 @@ public class EnergyScan extends Panel {
update();
//loadConfig();
}
@Override
public void onStateChange(State state, State former) {
setEnabled(state == State.Ready);
}
long scanStartTimestamp;
@Override
public void onExecutedFile(String fileName, Object result) {
try {
@@ -113,34 +113,34 @@ public class EnergyScan extends Panel {
showException(ex);
}
}
@Override
protected void doUpdate() {
plot();
}
void stopScan() throws Exception {
evalAsync("caput('START', 'STOP')");
}
Path getConfigFile() {
return Paths.get(getController().getSetup().getConfigPath(), "energy_scan.properties");
}
enum Mode {
plus,
minus,
lh,
lv
}
Mode[] batch;
int batchIndex;
LinePlotBase scanPlot;
LinePlotSeries scanSeries;
@Override
public void setEnabled(boolean value) {
super.setEnabled(value);
@@ -154,7 +154,7 @@ public class EnergyScan extends Panel {
buttonPlot.setEnabled(value);
checkParameterControls();
}
void checkParameterControls() {
boolean enabled = isEnabled() && (comboRunType.getSelectedIndex() == 0);
for (Component c : panelParameters.getComponents()) {
@@ -164,7 +164,7 @@ public class EnergyScan extends Panel {
}
spinnerAlpha.setEnabled(enabled && comboMode.getSelectedItem().equals("LINEAR"));
}
void plot() {
try {
if ((scanPlot != null) && (scanSeries != null) && scanPlot.isShowing() && (count != null)) {
@@ -214,7 +214,7 @@ public class EnergyScan extends Panel {
ex.printStackTrace();
}
}
void loadConfig() {
DefaultComboBoxModel model = (DefaultComboBoxModel) comboSetup.getModel();
model.removeAllElements();
@@ -230,7 +230,7 @@ public class EnergyScan extends Panel {
} catch (Exception ex) {
}
}
String expandPath(String path) {
long time = System.currentTimeMillis();
String mode;
@@ -241,7 +241,7 @@ public class EnergyScan extends Panel {
} else {
mode = "lin_" + String.format("%1.0f", (Double) spinnerAlpha.getValue());
}
path = path.replaceAll("\\{date\\}", Chrono.getTimeStr(time, "YYYYMMdd"));
path = path.replaceAll("\\{time\\}", Chrono.getTimeStr(time, "HHmmss"));
path = path.replaceAll("\\{year\\}", Chrono.getTimeStr(time, "YYYY"));
@@ -251,7 +251,7 @@ public class EnergyScan extends Panel {
path = path.replaceAll("\\{mode\\}", mode);
return path;
}
void setMode(Mode mode) {
switch (mode) {
case plus:
@@ -274,11 +274,11 @@ public class EnergyScan extends Panel {
return;
}
}
boolean isManualRun() {
return (comboRunType.getSelectedIndex() == 0);
}
void setElement() throws Exception {
Properties prop = new Properties();
prop.load(new FileInputStream(getConfigFile().toFile()));
@@ -292,13 +292,13 @@ public class EnergyScan extends Panel {
spinnerE2.setValue(Double.valueOf(tokens[1].trim()));
spinnerTime.setValue(Double.valueOf(tokens[2].trim()));
spinnerDelay.setValue(Double.valueOf(tokens[3].trim()));
offsets[0] = Double.valueOf(tokens[4].trim());
offsets[1] = Double.valueOf(tokens[5].trim());
offsets[2] = Double.valueOf(tokens[6].trim());
offsets[3] = Double.valueOf(tokens[7].trim());
}
void setRunType() throws Exception {
switch (comboRunType.getSelectedIndex()) {
case 0: //Manual
@@ -330,7 +330,7 @@ public class EnergyScan extends Panel {
}
checkParameterControls();
}
void run() throws ControllerStateException {
HashMap args = new HashMap();
Double e1 = (Double) spinnerE1.getValue();
@@ -342,26 +342,35 @@ public class EnergyScan extends Panel {
args.put("MODE", comboMode.getSelectedItem().toString());
args.put("OFFSET", (Double) spinnerOffset.getValue());
args.put("ALPHA", (Double) spinnerAlpha.getValue());
String file = expandPath(textFile.getText());
args.put("FILE", file);
String folder = expandPath(textFolder.getText());
args.put("FOLDER", folder);
scanStartTimestamp = System.currentTimeMillis();
runAsync("EnergyScan", args);
buttonAbort.setEnabled(true);
runAsync("EnergyScan", args).handle((ok, ex) -> {
buttonAbort.setEnabled(false);
if ((ex != null) && (ex instanceof Exception)){
showException((Exception) ex);
}
return ok;
});
if (scanPlot != null) {
scanPlot.getAxis(Plot.AxisId.X).setRange(Math.min(e1, e2), Math.max(e1, e2));
}
}
void startPlot() throws Exception {
PlotDescriptor descriptors = new PlotDescriptor("Energy Scan");
ArrayList<LinePlot> plots = getController().plot(new PlotDescriptor[]{descriptors}, null);
scanPlot = (LinePlotBase) plots.get(0);
scanSeries = scanPlot.getSeries(0);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
@@ -720,6 +729,7 @@ public class EnergyScan extends Panel {
});
buttonAbort.setText("Abort");
buttonAbort.setEnabled(false);
buttonAbort.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonAbortActionPerformed(evt);
@@ -823,21 +833,21 @@ public class EnergyScan extends Panel {
showException(ex);
}
}//GEN-LAST:event_comboSetupActionPerformed
EditorDialog dlgConfig;
private void buttonConfigureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConfigureActionPerformed
try {
//Desktop.getDesktop().open(getConfigFile().toFile());
if ((dlgConfig==null) || (!dlgConfig.isShowing())){
if ((dlgConfig == null) || (!dlgConfig.isShowing())) {
String[] columns = new String[]{"Element", "E1", "E2", "Time", "Delay", "OffPlus", "OffMinus", "OffLH", "OffLV"};
Class[] types = new Class[]{String.class, Double.class, Double.class, Double.class, Double.class, Double.class, Double.class, Double.class, Double.class};
DsvEditor editor = new DsvEditor(columns , types, " ");
dlgConfig = editor.getDialog(getView(),false);
DsvEditor editor = new DsvEditor(columns, types, " ");
dlgConfig = editor.getDialog(getView(), false);
editor.load(getConfigFile().toString());
editor.setTitle("Energy Scan Configuration");
}
dlgConfig.setSize(680, 320);
showWindow(dlgConfig);
dlgConfig.setSize(680, 320);
showWindow(dlgConfig);
} catch (Exception ex) {
showException(ex);
}
+25 -9
View File
@@ -45,20 +45,29 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace pref="30" max="32767" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spinnerE2" linkSize="2" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="30" max="32767" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spinnerE2" linkSize="2" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spinnerE1" linkSize="2" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="45" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="spinnerE1" linkSize="2" min="-2" max="-2" attributes="0"/>
<Component id="jRadioButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="45" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
@@ -122,6 +131,7 @@
<Group type="103" groupAlignment="3" attributes="0">
<Component id="spinnerSleep" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel9" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jRadioButton1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
@@ -207,6 +217,11 @@
<Property name="text" type="java.lang.String" value="End Field:"/>
</Properties>
</Component>
<Component class="javax.swing.JRadioButton" name="jRadioButton1">
<Properties>
<Property name="text" type="java.lang.String" value="jRadioButton1"/>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="jPanel3">
@@ -255,6 +270,7 @@
<Component class="javax.swing.JButton" name="buttonAbort">
<Properties>
<Property name="text" type="java.lang.String" value="Abort"/>
<Property name="enabled" type="boolean" value="false"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="buttonAbortActionPerformed"/>
+37 -11
View File
@@ -12,6 +12,8 @@ import javax.swing.JLabel;
*
*/
public class HystScan extends Panel {
final static boolean POP_SCRIPT_EXCEPTIONS = true;
public HystScan() {
initComponents();
@@ -67,6 +69,7 @@ public class HystScan extends Panel {
spinnerStartField = new javax.swing.JSpinner();
spinnerEndField = new javax.swing.JSpinner();
jLabel4 = new javax.swing.JLabel();
jRadioButton1 = new javax.swing.JRadioButton();
jPanel3 = new javax.swing.JPanel();
buttonExecute = new javax.swing.JButton();
buttonAbort = new javax.swing.JButton();
@@ -103,22 +106,30 @@ public class HystScan extends Panel {
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
jLabel4.setText("End Field:");
jRadioButton1.setText("jRadioButton1");
javax.swing.GroupLayout panelParametersLayout = new javax.swing.GroupLayout(panelParameters);
panelParameters.setLayout(panelParametersLayout);
panelParametersLayout.setHorizontalGroup(
panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelParametersLayout.createSequentialGroup()
.addContainerGap(30, Short.MAX_VALUE)
.addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelParametersLayout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spinnerE2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(30, Short.MAX_VALUE)
.addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(panelParametersLayout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spinnerE2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(panelParametersLayout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spinnerE1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE))
.addGroup(panelParametersLayout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spinnerE1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
.addContainerGap()
.addComponent(jRadioButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelParametersLayout.createSequentialGroup()
.addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@@ -170,7 +181,8 @@ public class HystScan extends Panel {
.addGap(5, 5, 5)
.addGroup(panelParametersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(spinnerSleep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel9))
.addComponent(jLabel9)
.addComponent(jRadioButton1))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
@@ -184,6 +196,7 @@ public class HystScan extends Panel {
});
buttonAbort.setText("Abort");
buttonAbort.setEnabled(false);
buttonAbort.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonAbortActionPerformed(evt);
@@ -230,6 +243,7 @@ public class HystScan extends Panel {
private void buttonExecuteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExecuteActionPerformed
try {
/*
HashMap args = new HashMap();
Double e1 = (Double) spinnerE1.getValue();
Double e2 = (Double) spinnerE2.getValue();
@@ -239,7 +253,18 @@ public class HystScan extends Panel {
args.put("END_FIELD", (Double) spinnerEndField.getValue());
args.put("RAMP_RATE", (Double) spinnerRampRate.getValue());
args.put("ENERGY_CHANGE_SLEEP", (Double) spinnerSleep.getValue());
runAsync("HystScan", args);
buttonAbort.setEnabled(true);
runAsync("HystScan", args).handle((ok, ex) -> {
*/
buttonAbort.setEnabled(true);
runAsync("tutorial/01_LineScan").handle((ok, ex) -> {
buttonAbort.setEnabled(false);
if ((ex != null) && (ex instanceof Exception)){
showException((Exception) ex);
}
return ok;
});
} catch (Exception ex) {
showException(ex);
@@ -260,6 +285,7 @@ public class HystScan extends Panel {
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel3;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JPanel panelParameters;
private javax.swing.JSpinner spinnerE1;
private javax.swing.JSpinner spinnerE2;