Closedown

This commit is contained in:
x07maop
2015-08-25 10:12:27 +02:00
parent 535685c3fe
commit 5adc24f116
5 changed files with 133 additions and 145 deletions

View File

@@ -2,11 +2,9 @@
* 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.State;
import java.awt.Component;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -14,7 +12,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.table.DefaultTableModel;
@@ -54,14 +51,13 @@ public class HystScan extends Panel {
@Override
public void setEnabled(boolean value) {
super.setEnabled(value);
buttonExecute.setEnabled(value);
buttonExecute.setEnabled(value);
tableEnergies.setEnabled(value);
for (Component c : panelParameters.getComponents()) {
if (!(c instanceof JLabel)) {
c.setEnabled(value);
}
}
//spinnerE3.setEnabled(value && checkE3.isSelected());
}
}
Path getConfigFile() {
@@ -107,6 +103,7 @@ public class HystScan extends Panel {
Mode[] batch;
int batchIndex;
double[] offsets = new double[2];
boolean reverseScan;
boolean isManualRun() {
@@ -146,18 +143,68 @@ public class HystScan extends Panel {
return;
}
}
void run() throws Exception {
String file = expandPath(textFile.getText());
eval("FILENAME = '" + file + "'");
void setRunType() throws Exception {
switch (comboRunType.getSelectedIndex()) {
case 0: //Manual
break;
case 1: //2-loop
setMode(Mode.plus);
break;
case 2: //4-loop
setMode(Mode.minus);
break;
HashMap args = new HashMap();
ArrayList<Double> energies = new ArrayList<>();
int rows = (Integer) spinnerEnergies.getValue();
((DefaultTableModel) tableEnergies.getModel()).setNumRows(rows);
for (int i = 0; i < tableEnergies.getRowCount(); i++) {
energies.add((Double) ((DefaultTableModel) tableEnergies.getModel()).getValueAt(i, 1));
}
args.put("ENERGIES", energies);
if (reverseScan){
getLogger().warning("Setting reverse scan");
args.put("START_FIELD", (Double) spinnerEndField.getValue());
args.put("END_FIELD", (Double) spinnerStartField.getValue());
} else {
args.put("START_FIELD", (Double) spinnerStartField.getValue());
args.put("END_FIELD", (Double) spinnerEndField.getValue());
}
args.put("RAMP_RATE", (Double) spinnerRampRate.getValue());
args.put("ENERGY_CHANGE_SLEEP", (Double) spinnerSleep.getValue());
args.put("MODE", comboMode.getSelectedItem().toString());
args.put("OFFSET", (Double) spinnerOffset.getValue());
buttonAbort.setEnabled(true);
buttonExecute.setEnabled(false);
runAsync("HystScan", args).handle((ok, ex) -> {
try{
buttonAbort.setEnabled(false);
try {
eval("FILENAME = None");
} catch (Exception ex1) {
Logger.getLogger(HystScan.class.getName()).log(Level.WARNING, null, ex1);
}
if (ex != null) {
throw ex;
} else {
if (batch != null) {
batchIndex++;
reverseScan = !reverseScan;
if (batchIndex >= batch.length) {
batch = null;
reverseScan = false;
} else {
setMode(batch[batchIndex]);
run();
}
}
}
} catch (Throwable t){
batch = null;
reverseScan = false;
getLogger().log(Level.WARNING, null, ex);
showException((Exception)ex);
}
return ok;
});
}
@@ -432,11 +479,6 @@ public class HystScan extends Panel {
jLabel12.setText("Run Type:");
comboRunType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Manual", "2-loop", "4-loop" }));
comboRunType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboRunTypeActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
@@ -457,12 +499,13 @@ public class HystScan extends Panel {
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(comboSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel12)
.addComponent(comboRunType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(comboRunType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(comboSetup, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11)))
.addContainerGap())
);
@@ -491,53 +534,20 @@ public class HystScan extends Panel {
private void buttonExecuteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExecuteActionPerformed
try {
String file = expandPath(textFile.getText());
eval("FILENAME = '" + file+"'");
HashMap args = new HashMap();
ArrayList<Double> energies = new ArrayList<>();
int rows = (Integer)spinnerEnergies.getValue();
((DefaultTableModel)tableEnergies.getModel()).setNumRows(rows);
for (int i=0; i<tableEnergies.getRowCount(); i++){
energies.add((Double)((DefaultTableModel)tableEnergies.getModel()).getValueAt(i, 1));
batchIndex = 0;
switch (comboRunType.getSelectedIndex()) {
case 1:
batch = new Mode[]{Mode.plus, Mode.minus};
setMode(batch[0]);
break;
case 2:
batch = new Mode[]{Mode.plus, Mode.minus, Mode.minus, Mode.plus};
setMode(batch[0]);
break;
default:
batch = null;
}
/*
Double e1 = (Double) spinnerE1.getValue();
Double e2 = (Double) spinnerE2.getValue();
//args.put("E1", e1);
//args.put("E2", e2);
energies.add(e1);
energies.add(e2);
if (checkE3.isSelected()){
Double e3 = (Double) spinnerE3.getValue();
energies.add(e3);
}
*/
args.put("ENERGIES", energies);
args.put("START_FIELD", (Double) spinnerStartField.getValue());
args.put("END_FIELD", (Double) spinnerEndField.getValue());
args.put("RAMP_RATE", (Double) spinnerRampRate.getValue());
args.put("ENERGY_CHANGE_SLEEP", (Double) spinnerSleep.getValue());
args.put("MODE", comboMode.getSelectedItem().toString());
args.put("OFFSET", (Double) spinnerOffset.getValue());
buttonAbort.setEnabled(true);
buttonExecute.setEnabled(false);
runAsync("HystScan", args).handle((ok, ex) -> {
buttonAbort.setEnabled(false);
if (ex != null) {
getLogger().log(Level.WARNING, null, ex);
}
try {
eval("FILENAME = None");
} catch (Exception ex1) {
Logger.getLogger(HystScan.class.getName()).log(Level.WARNING, null, ex1);
}
return ok;
});
run();
} catch (Exception ex) {
showException(ex);
}
@@ -555,26 +565,12 @@ public class HystScan extends Panel {
try {
if (comboSetup.getSelectedItem()!=null){
setElement();
if (!isManualRun()) {
setRunType();
}
}
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_comboSetupActionPerformed
private void comboRunTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboRunTypeActionPerformed
try {
if (!isManualRun()) {
setElement();
}
setRunType();
} catch (Exception ex) {
showException(ex);
}
}//GEN-LAST:event_comboRunTypeActionPerformed
private void spinnerEnergiesStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spinnerEnergiesStateChanged
int rows = (Integer)spinnerEnergies.getValue();
((DefaultTableModel)tableEnergies.getModel()).setNumRows(rows);