Fix Queues
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
|
||||
import ch.psi.pshell.core.JsonSerializer;
|
||||
import ch.psi.pshell.epics.Positioner;
|
||||
import ch.psi.pshell.ui.PanelProcessor;
|
||||
import ch.psi.pshell.ui.ScriptProcessor;
|
||||
import ch.psi.utils.EncoderJson;
|
||||
import ch.psi.utils.IO;
|
||||
import ch.psi.utils.State;
|
||||
import ch.psi.utils.swing.SwingUtils;
|
||||
@@ -12,6 +11,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JFileChooser;
|
||||
@@ -21,7 +21,7 @@ import javax.swing.table.DefaultTableModel;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class EnergyScan extends PanelProcessor {
|
||||
public class EnergyScan extends ScriptProcessor {
|
||||
|
||||
final DefaultTableModel model;
|
||||
Positioner energy;
|
||||
@@ -38,6 +38,11 @@ public class EnergyScan extends PanelProcessor {
|
||||
return "Energy Scan";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSave() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createMenuNew() {
|
||||
return true;
|
||||
@@ -71,9 +76,10 @@ public class EnergyScan extends PanelProcessor {
|
||||
|
||||
@Override
|
||||
public void onStateChange(State state, State former) {
|
||||
buttonStart.setEnabled(state == State.Ready);
|
||||
buttonAbort.setEnabled(state.isProcessing());
|
||||
buttonStart.setEnabled(state == State.Ready);
|
||||
buttonAbort.setEnabled((state == State.Busy) && isRunning());
|
||||
buttonScienta.setEnabled(state.isInitialized());
|
||||
buttonAddToQueue.setEnabled(buttonStart.isEnabled());
|
||||
updateSeq();
|
||||
}
|
||||
|
||||
@@ -104,9 +110,11 @@ public class EnergyScan extends PanelProcessor {
|
||||
Double stop = (Double) model.getValueAt(i, 1);
|
||||
Double step = (Double) model.getValueAt(i, 2);
|
||||
if (Double.isNaN(start) || Double.isNaN(stop) || Double.isNaN(step)
|
||||
|| (start >= stop) || (step < 0)
|
||||
|| (step < 0)
|
||||
|| (start < energy.getMinValue())
|
||||
|| (stop > energy.getMaxValue())) {
|
||||
|| (stop > energy.getMaxValue())
|
||||
|| (start > energy.getMaxValue())
|
||||
|| (stop < energy.getMinValue())) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
@@ -118,11 +126,66 @@ public class EnergyScan extends PanelProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
checkValues();
|
||||
String lastOutput = getContext().getDataManager().getLastOutput();
|
||||
public void saveAs(String fileName) throws IOException {
|
||||
currentFile = new File(fileName);
|
||||
ArrayList data = new ArrayList();
|
||||
data.add(new Object[][]{new Object[]{textName.getText()}});
|
||||
data.add(model.getDataVector());
|
||||
data.add(spinnerPasses.getValue());
|
||||
String json = EncoderJson.encode(data, true);
|
||||
Files.write(currentFile.toPath(), json.getBytes());
|
||||
}
|
||||
|
||||
HashMap args = new HashMap();
|
||||
@Override
|
||||
public void open(String fileName) throws IOException {
|
||||
if (fileName==null){
|
||||
currentFile = null;
|
||||
textName.setText("");
|
||||
model.setRowCount(0);
|
||||
spinnerPasses.setValue(1);
|
||||
} else {
|
||||
Path path = Paths.get(fileName);
|
||||
String json = new String(Files.readAllBytes(path));
|
||||
currentFile = path.toFile();
|
||||
Object[][][] vector = (Object[][][]) EncoderJson.decode(json, Object[][][].class);
|
||||
textName.setText(String.valueOf(vector[0][0][0]));
|
||||
model.setDataVector(vector[1], SwingUtils.getTableColumnNames(table));
|
||||
spinnerPasses.setValue((vector.length>2) ? (Integer)vector[2][0][0] : 1);
|
||||
}
|
||||
}
|
||||
|
||||
String lastOutput;
|
||||
|
||||
@Override
|
||||
protected void onStartingExecution(Map<String, Object> args){
|
||||
getLogger().warning(this.getFileName());
|
||||
lastOutput = getContext().getDataManager().getLastOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFinishedExecution(Map<String, Object> args, Object ret, Throwable t){
|
||||
if (checkAutoSaveArgs.isSelected()) {
|
||||
//Save scan attributes
|
||||
String output = getContext().getDataManager().getLastOutput();
|
||||
if ((output != null) && !output.isEmpty() && !output.equals(lastOutput)) {
|
||||
try {
|
||||
saveAs(output + "." + FILE_EXTENSION);
|
||||
} catch (IOException e) {
|
||||
Logger.getLogger(EnergyScan.class.getName()).log(Level.WARNING, null, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScript() {
|
||||
return "templates/EnergyScan";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getArgs() {
|
||||
HashMap<String, Object> args = new HashMap<>();
|
||||
checkValues();
|
||||
ArrayList regions = new ArrayList();
|
||||
for (int i = 0; i < model.getRowCount(); i++) {
|
||||
ArrayList region = new ArrayList();
|
||||
@@ -133,51 +196,11 @@ public class EnergyScan extends PanelProcessor {
|
||||
}
|
||||
args.put("FILE", null);
|
||||
args.put("NAME", getScanName());
|
||||
args.put("REGIONS", regions);
|
||||
this.runAsync("templates/EnergyScan", args).handle((ret, ex) -> {
|
||||
if (ex != null) {
|
||||
}
|
||||
if (checkAutoSaveArgs.isSelected()) {
|
||||
//Save scan attributes
|
||||
String output = getContext().getDataManager().getLastOutput();
|
||||
if ((output != null) && !output.isEmpty() && !output.equals(lastOutput)) {
|
||||
try {
|
||||
saveAs(output + "." + FILE_EXTENSION);
|
||||
} catch (IOException e) {
|
||||
Logger.getLogger(EnergyScan.class.getName()).log(Level.WARNING, null, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
args.put("REGIONS", regions);
|
||||
args.put("PASSES", spinnerPasses.getValue());
|
||||
return args;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveAs(String fileName) throws IOException {
|
||||
currentFile = new File(fileName);
|
||||
ArrayList data = new ArrayList();
|
||||
data.add(new Object[][]{new Object[]{textName.getText()}});
|
||||
data.add(model.getDataVector());
|
||||
String json = JsonSerializer.encode(data, true);
|
||||
Files.write(currentFile.toPath(), json.getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(String fileName) throws IOException {
|
||||
if (fileName==null){
|
||||
currentFile = null;
|
||||
textName.setText("");
|
||||
model.setRowCount(0);
|
||||
} else {
|
||||
Path path = Paths.get(fileName);
|
||||
String json = new String(Files.readAllBytes(path));
|
||||
currentFile = path.toFile();
|
||||
Object[][][] vector = (Object[][][]) JsonSerializer.decode(json, Object[][][].class);
|
||||
textName.setText(String.valueOf(vector[0][0][0]));
|
||||
model.setDataVector(vector[1], SwingUtils.getTableColumnNames(table));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
@@ -198,6 +221,10 @@ public class EnergyScan extends PanelProcessor {
|
||||
jLabel1 = new javax.swing.JLabel();
|
||||
buttonOpen = new javax.swing.JButton();
|
||||
buttonSave = new javax.swing.JButton();
|
||||
buttonAddToQueue = new javax.swing.JButton();
|
||||
jLabel3 = new javax.swing.JLabel();
|
||||
spinnerPasses = new javax.swing.JSpinner();
|
||||
buttonClear = new javax.swing.JButton();
|
||||
jLabel2 = new javax.swing.JLabel();
|
||||
textFileId = new javax.swing.JTextField();
|
||||
buttonResetId = new javax.swing.JButton();
|
||||
@@ -285,7 +312,7 @@ public class EnergyScan extends PanelProcessor {
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
|
||||
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(buttonAdd)
|
||||
@@ -309,6 +336,24 @@ public class EnergyScan extends PanelProcessor {
|
||||
}
|
||||
});
|
||||
|
||||
buttonAddToQueue.setText("Add To Queue");
|
||||
buttonAddToQueue.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonAddToQueueActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jLabel3.setText("Passes:");
|
||||
|
||||
spinnerPasses.setModel(new javax.swing.SpinnerNumberModel(1, 1, 100, 1));
|
||||
|
||||
buttonClear.setText("Clear");
|
||||
buttonClear.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonClearActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
||||
jPanel2.setLayout(jPanel2Layout);
|
||||
jPanel2Layout.setHorizontalGroup(
|
||||
@@ -316,17 +361,31 @@ public class EnergyScan extends PanelProcessor {
|
||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
||||
.addComponent(jLabel1)
|
||||
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
||||
.addComponent(jLabel1)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(textName)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonClear)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonOpen)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonSave)))
|
||||
.addContainerGap())
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
|
||||
.addComponent(jLabel3)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(textName)
|
||||
.addGap(18, 18, 18)
|
||||
.addComponent(buttonOpen)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonSave)))
|
||||
.addContainerGap())
|
||||
.addComponent(spinnerPasses, 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(buttonAddToQueue)
|
||||
.addGap(26, 26, 26))))
|
||||
);
|
||||
|
||||
jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonClear, buttonOpen, buttonSave});
|
||||
|
||||
jPanel2Layout.setVerticalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel2Layout.createSequentialGroup()
|
||||
@@ -335,10 +394,16 @@ public class EnergyScan extends PanelProcessor {
|
||||
.addComponent(textName)
|
||||
.addComponent(buttonOpen)
|
||||
.addComponent(buttonSave)
|
||||
.addComponent(jLabel1))
|
||||
.addComponent(jLabel1)
|
||||
.addComponent(buttonClear))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGap(12, 12, 12))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(buttonAddToQueue)
|
||||
.addComponent(jLabel3)
|
||||
.addComponent(spinnerPasses, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
jLabel2.setText("File ID:");
|
||||
@@ -362,11 +427,11 @@ public class EnergyScan extends PanelProcessor {
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addGap(0, 9, Short.MAX_VALUE)
|
||||
.addComponent(buttonStart, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(33, 33, 33)
|
||||
.addComponent(buttonAbort)
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap(19, Short.MAX_VALUE))
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
@@ -401,7 +466,7 @@ public class EnergyScan extends PanelProcessor {
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(buttonScienta)
|
||||
.addComponent(buttonResetId))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, 32, Short.MAX_VALUE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(buttonStart)
|
||||
.addComponent(buttonAbort))
|
||||
@@ -497,9 +562,27 @@ public class EnergyScan extends PanelProcessor {
|
||||
}
|
||||
}//GEN-LAST:event_buttonResetIdActionPerformed
|
||||
|
||||
private void buttonAddToQueueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddToQueueActionPerformed
|
||||
try {
|
||||
queue(); //TODO: Data/file
|
||||
} catch (Exception ex) {
|
||||
showException( ex);
|
||||
}
|
||||
}//GEN-LAST:event_buttonAddToQueueActionPerformed
|
||||
|
||||
private void buttonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClearActionPerformed
|
||||
try {
|
||||
open(null);
|
||||
} catch (Exception ex) {
|
||||
showException( ex);
|
||||
}
|
||||
}//GEN-LAST:event_buttonClearActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton buttonAbort;
|
||||
private javax.swing.JButton buttonAdd;
|
||||
private javax.swing.JButton buttonAddToQueue;
|
||||
private javax.swing.JButton buttonClear;
|
||||
private javax.swing.JButton buttonDelete;
|
||||
private javax.swing.JButton buttonOpen;
|
||||
private javax.swing.JButton buttonResetId;
|
||||
@@ -510,10 +593,12 @@ public class EnergyScan extends PanelProcessor {
|
||||
private javax.swing.JEditorPane jEditorPane1;
|
||||
private javax.swing.JLabel jLabel1;
|
||||
private javax.swing.JLabel jLabel2;
|
||||
private javax.swing.JLabel jLabel3;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel jPanel2;
|
||||
private javax.swing.JScrollPane jScrollPane1;
|
||||
private javax.swing.JScrollPane jScrollPane2;
|
||||
private javax.swing.JSpinner spinnerPasses;
|
||||
private javax.swing.JTable table;
|
||||
private javax.swing.JTextField textFileId;
|
||||
private javax.swing.JTextField textName;
|
||||
|
||||
Reference in New Issue
Block a user