Closedown
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user