Fix Queues

This commit is contained in:
gac-ISS
2023-01-11 10:39:12 +01:00
parent c2b9b275c7
commit 2fb24afec1
8 changed files with 572 additions and 394 deletions

View File

@@ -1,7 +1,7 @@
import ch.psi.pshell.core.JsonSerializer;
import ch.psi.pshell.scan.Scan;
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 java.io.File;
@@ -11,18 +11,17 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.CompletableFuture;
import java.util.Map;
import java.util.logging.Level;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
/**
*
*/
public class TimeResolved extends PanelProcessor {
public class TimeResolved extends ScriptProcessor {
File currentFile;
public static final String FILE_EXTENSION = "tmr";
CompletableFuture taskFuture;
public TimeResolved() {
initComponents();
@@ -33,6 +32,11 @@ public class TimeResolved extends PanelProcessor {
return "Time Resolved";
}
@Override
public boolean canSave() {
return true;
}
@Override
public boolean createMenuNew() {
return true;
@@ -67,15 +71,16 @@ public class TimeResolved extends PanelProcessor {
@Override
public void onStateChange(State state, State former) {
buttonStart.setEnabled(state == State.Ready);
buttonAbort.setEnabled(state.isProcessing());
buttonAbort.setEnabled((state == State.Busy) && isRunning());
buttonScienta.setEnabled(state.isInitialized());
buttonAddToQueue.setEnabled(buttonStart.isEnabled());
updateSeq();
}
@Override
public void onTimer() {
try{
if (taskFuture!=null){
if (isRunning()){
Scan scan = getContext().getExecutionPars().getCurrentScan();
if (scan!=null){
int index = scan.getRecordIndex();
@@ -112,29 +117,26 @@ public class TimeResolved extends PanelProcessor {
}
@Override
public void execute() throws Exception {
String lastOutput = getContext().getDataManager().getLastOutput();
public String getScript() {
return "templates/TimeResolved";
}
HashMap args = new HashMap();
@Override
public Map<String, Object> getArgs() {
HashMap<String, Object> args = new HashMap<>();
args.put("FILE", null);
args.put("NAME", getScanName());
args.put("SCANS", spinnerScans.getValue());
taskFuture = runAsync("templates/TimeResolved", args);
taskFuture.handle((ret, ex) -> {
if (ex != null) {
}
taskFuture = null;
return ret;
});
return args;
}
@Override
public void saveAs(String fileName) throws IOException {
currentFile = new File(fileName);
ArrayList data = new ArrayList();
data.add(textName.getText());
data.add(spinnerScans.getValue());
String json = JsonSerializer.encode(data, true);
String json = EncoderJson.encode(data, true);
Files.write(currentFile.toPath(), json.getBytes());
}
@@ -148,7 +150,7 @@ public class TimeResolved extends PanelProcessor {
Path path = Paths.get(fileName);
String json = new String(Files.readAllBytes(path));
currentFile = path.toFile();
Object[] vector = (Object[]) JsonSerializer.decode(json, Object[].class);
Object[] vector = (Object[]) EncoderJson.decode(json, Object[].class);
textName.setText(String.valueOf(vector[0]));
spinnerScans.setValue(vector[1]);
}
@@ -170,6 +172,7 @@ public class TimeResolved extends PanelProcessor {
textName = new javax.swing.JTextField();
buttonOpen = new javax.swing.JButton();
buttonSave = new javax.swing.JButton();
buttonAddToQueue = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
textFileId = new javax.swing.JTextField();
buttonResetId = new javax.swing.JButton();
@@ -221,6 +224,13 @@ public class TimeResolved extends PanelProcessor {
}
});
buttonAddToQueue.setText("Add To Queue");
buttonAddToQueue.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
buttonAddToQueueActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
@@ -241,6 +251,10 @@ public class TimeResolved extends PanelProcessor {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(buttonSave)))
.addGap(14, 14, 14))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(buttonAddToQueue)
.addContainerGap())
);
jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel3});
@@ -258,7 +272,9 @@ public class TimeResolved extends PanelProcessor {
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(spinnerScans, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(100, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 66, Short.MAX_VALUE)
.addComponent(buttonAddToQueue)
.addContainerGap())
);
jLabel2.setText("File ID:");
@@ -404,8 +420,17 @@ public class TimeResolved extends PanelProcessor {
}
}//GEN-LAST:event_buttonSaveActionPerformed
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
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton buttonAbort;
private javax.swing.JButton buttonAddToQueue;
private javax.swing.JButton buttonOpen;
private javax.swing.JButton buttonResetId;
private javax.swing.JButton buttonSave;