diff --git a/config/plugins.properties b/config/plugins.properties index d79e0f3..ad9eba2 100644 --- a/config/plugins.properties +++ b/config/plugins.properties @@ -1,2 +1,3 @@ +XPS.java=enabled TimeResolved.java=enabled EnergyScan.java=enabled diff --git a/config/variables.properties b/config/variables.properties index 7b38302..fc21a38 100644 --- a/config/variables.properties +++ b/config/variables.properties @@ -1,4 +1,4 @@ -#Wed Jan 11 10:35:51 CET 2023 +#Wed Jan 11 10:54:13 CET 2023 LastRunDate=230111 -FileSequentialNumber=99 -DaySequentialNumber=6 +FileSequentialNumber=100 +DaySequentialNumber=7 diff --git a/plugins/EnergyScan.form b/plugins/EnergyScan.form index ce2be2e..3946d56 100644 --- a/plugins/EnergyScan.form +++ b/plugins/EnergyScan.form @@ -131,22 +131,17 @@ - - - - - - - - - - - - - - - + + + + + + + + + + @@ -154,9 +149,9 @@ - + @@ -202,12 +197,12 @@ - - - + + + + - @@ -221,7 +216,7 @@ - + @@ -247,15 +242,19 @@ + + + + - + - + - + diff --git a/plugins/EnergyScan.java b/plugins/EnergyScan.java index acd24b9..c7efc7d 100644 --- a/plugins/EnergyScan.java +++ b/plugins/EnergyScan.java @@ -31,6 +31,7 @@ public class EnergyScan extends ScriptProcessor { public EnergyScan() { initComponents(); model = (DefaultTableModel) table.getModel(); + updateButtons(); } @Override @@ -80,6 +81,7 @@ public class EnergyScan extends ScriptProcessor { buttonAbort.setEnabled((state == State.Busy) && isRunning()); buttonScienta.setEnabled(state.isInitialized()); buttonAddToQueue.setEnabled(buttonStart.isEnabled()); + updateButtons(); updateSeq(); } @@ -134,6 +136,7 @@ public class EnergyScan extends ScriptProcessor { data.add(spinnerPasses.getValue()); String json = EncoderJson.encode(data, true); Files.write(currentFile.toPath(), json.getBytes()); + updateButtons(); } @Override @@ -152,6 +155,7 @@ public class EnergyScan extends ScriptProcessor { model.setDataVector(vector[1], SwingUtils.getTableColumnNames(table)); spinnerPasses.setValue((vector.length>2) ? (Integer)vector[2][0][0] : 1); } + updateButtons(); } String lastOutput; @@ -201,6 +205,18 @@ public class EnergyScan extends ScriptProcessor { return args; } + protected void updateButtons() { + boolean editing = !isExecuting(); + int rows = model.getRowCount(); + int cur = table.getSelectedRow(); + buttonDelete.setEnabled((rows > 0) && (cur >= 0) && editing); + buttonInsert.setEnabled(editing); + buttonClear.setEnabled(editing); + buttonOpen.setEnabled(editing); + table.setEnabled(editing); + textName.setEnabled(editing); + } + @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { @@ -216,7 +232,7 @@ public class EnergyScan extends ScriptProcessor { jPanel1 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); table = new javax.swing.JTable(); - buttonAdd = new javax.swing.JButton(); + buttonInsert = new javax.swing.JButton(); buttonDelete = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); buttonOpen = new javax.swing.JButton(); @@ -274,12 +290,22 @@ public class EnergyScan extends ScriptProcessor { return types [columnIndex]; } }); + table.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseReleased(java.awt.event.MouseEvent evt) { + tableMouseReleased(evt); + } + }); + table.addKeyListener(new java.awt.event.KeyAdapter() { + public void keyReleased(java.awt.event.KeyEvent evt) { + tableKeyReleased(evt); + } + }); jScrollPane1.setViewportView(table); - buttonAdd.setText("Add"); - buttonAdd.addActionListener(new java.awt.event.ActionListener() { + buttonInsert.setText("Insert"); + buttonInsert.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - buttonAddActionPerformed(evt); + buttonInsertActionPerformed(evt); } }); @@ -297,16 +323,16 @@ public class EnergyScan extends ScriptProcessor { .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(buttonAdd) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(buttonInsert) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonDelete) - .addGap(0, 0, Short.MAX_VALUE))) + .addComponent(buttonDelete))) .addContainerGap()) ); - jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAdd, buttonDelete}); + jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonDelete, buttonInsert}); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -315,7 +341,7 @@ public class EnergyScan extends ScriptProcessor { .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) + .addComponent(buttonInsert) .addComponent(buttonDelete)) .addContainerGap()) ); @@ -361,27 +387,24 @@ public class EnergyScan extends ScriptProcessor { .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() - .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()) + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textName, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonClear) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonOpen) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonSave)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .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)))) + .addComponent(buttonAddToQueue))) + .addContainerGap()) ); jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonClear, buttonOpen, buttonSave}); @@ -490,19 +513,21 @@ public class EnergyScan extends ScriptProcessor { } }//GEN-LAST:event_buttonAbortActionPerformed - private void buttonAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddActionPerformed + private void buttonInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonInsertActionPerformed try { //model.addRow(new Object[]{energy.getMinValue(), energy.getMaxValue(), 10.0}); model.addRow(new Object[]{500.0, 1000.0, 100.0}); + updateButtons(); } catch (Exception ex) { showException(ex); } - }//GEN-LAST:event_buttonAddActionPerformed + }//GEN-LAST:event_buttonInsertActionPerformed private void buttonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDeleteActionPerformed try { if ((model.getRowCount() > 0) && (table.getSelectedRow() >= 0)) { model.removeRow(table.getSelectedRow()); + updateButtons(); } } catch (Exception ex) { showException(ex); @@ -578,12 +603,20 @@ public class EnergyScan extends ScriptProcessor { } }//GEN-LAST:event_buttonClearActionPerformed + private void tableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseReleased + updateButtons(); + }//GEN-LAST:event_tableMouseReleased + + private void tableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyReleased + updateButtons(); + }//GEN-LAST:event_tableKeyReleased + // 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 buttonInsert; private javax.swing.JButton buttonOpen; private javax.swing.JButton buttonResetId; private javax.swing.JButton buttonSave; diff --git a/plugins/TimeResolved.form b/plugins/TimeResolved.form index 659a5a6..34c58ae 100644 --- a/plugins/TimeResolved.form +++ b/plugins/TimeResolved.form @@ -139,7 +139,9 @@ - + + + @@ -163,6 +165,7 @@ + @@ -220,6 +223,14 @@ + + + + + + + + diff --git a/plugins/TimeResolved.java b/plugins/TimeResolved.java index b3164df..5f08b8e 100644 --- a/plugins/TimeResolved.java +++ b/plugins/TimeResolved.java @@ -74,6 +74,13 @@ public class TimeResolved extends ScriptProcessor { buttonAbort.setEnabled((state == State.Busy) && isRunning()); buttonScienta.setEnabled(state.isInitialized()); buttonAddToQueue.setEnabled(buttonStart.isEnabled()); + + boolean editing = !isExecuting(); + buttonClear.setEnabled(editing); + buttonOpen.setEnabled(editing); + textName.setEnabled(editing); + spinnerScans.setEnabled(editing); + updateSeq(); } @@ -173,6 +180,7 @@ public class TimeResolved extends ScriptProcessor { buttonOpen = new javax.swing.JButton(); buttonSave = new javax.swing.JButton(); buttonAddToQueue = new javax.swing.JButton(); + buttonClear = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); textFileId = new javax.swing.JTextField(); buttonResetId = new javax.swing.JButton(); @@ -231,6 +239,13 @@ public class TimeResolved extends ScriptProcessor { } }); + 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( @@ -246,7 +261,9 @@ public class TimeResolved extends ScriptProcessor { .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(textName) - .addGap(18, 18, 18) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonClear) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonOpen) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonSave))) @@ -267,7 +284,8 @@ public class TimeResolved extends ScriptProcessor { .addComponent(textName) .addComponent(jLabel1) .addComponent(buttonOpen) - .addComponent(buttonSave)) + .addComponent(buttonSave) + .addComponent(buttonClear)) .addGap(11, 11, 11) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) @@ -428,9 +446,18 @@ public class TimeResolved extends ScriptProcessor { } }//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 buttonAddToQueue; + private javax.swing.JButton buttonClear; private javax.swing.JButton buttonOpen; private javax.swing.JButton buttonResetId; private javax.swing.JButton buttonSave; diff --git a/plugins/XPS.form b/plugins/XPS.form new file mode 100644 index 0000000..a20e4d9 --- /dev/null +++ b/plugins/XPS.form @@ -0,0 +1,320 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+ + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/plugins/XPS.java b/plugins/XPS.java new file mode 100644 index 0000000..2ae20e9 --- /dev/null +++ b/plugins/XPS.java @@ -0,0 +1,731 @@ + +import ch.psi.pshell.scan.Scan; +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.StandardDialog; +import ch.psi.utils.swing.SwingUtils; +import java.awt.Window; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.nio.file.Files; +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 javax.swing.JFileChooser; +import javax.swing.filechooser.FileNameExtensionFilter; +import javax.swing.table.DefaultTableModel; +/** + * + */ +public class XPS extends ScriptProcessor { + + File currentFile; + final DefaultTableModel model; + public static final String FILE_EXTENSION = "xps"; + + public XPS() { + initComponents(); + model = (DefaultTableModel) table.getModel(); + + table.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + try { + if ((e.getClickCount() == 2) && (!e.isPopupTrigger())) { + if (table.isEnabled()){ + int row = table.getSelectedRow(); + if ((model.getRowCount()>0) && (row>=0)){ + row = table.convertRowIndexToModel(row); + + String name = (String) model.getValueAt(row, 1); + String json = (String) model.getValueAt(row, 2); + Map pars = (Map) EncoderJson.decode(json, Map.class); + pars.put("name", name); + Map newPars = showScientaParametersDialog(pars); + if (newPars!=null){ + name = (String) newPars.get("name"); + if (name!=null){ + newPars.remove("name"); + json = EncoderJson.encode(newPars, true); + //showMessage(name, json); + model.setValueAt(name, row, 1); + model.setValueAt(json, row, 2); + } + } + } + } + } + } catch (Exception ex) { + showException(ex); + } + } + }); + table.getColumnModel().getColumn(0).setMaxWidth(60); + table.getColumnModel().getColumn(0).setResizable(false); + updateButtons(); + } + + @Override + public String getType() { + return "XPS"; + } + + @Override + public boolean canSave() { + return true; + } + + @Override + public String getFileName() { + return (currentFile==null) ? null : currentFile.toString(); + } + @Override + public boolean createMenuNew() { + return true; + } + + @Override + public boolean createFilePanel() { + return true; + } + + @Override + public String getDescription() { + return "XPS scan definition file (*." + FILE_EXTENSION + ")"; + } + + @Override + public String[] getExtensions() { + return new String[]{FILE_EXTENSION}; + } + + @Override + public String getHomePath() { + return "{home}/parameters"; + } + + //Overridable callbacks + @Override + public void onInitialize(int runCount) { + this.startTimer(1000); + } + + @Override + public void onStateChange(State state, State former) { + buttonStart.setEnabled(state == State.Ready); + buttonAbort.setEnabled((state == State.Busy) && isRunning()); + buttonScienta.setEnabled(state.isInitialized()); + buttonAddToQueue.setEnabled(buttonStart.isEnabled()); + updateButtons(); + updateSeq(); + } + + @Override + public void onTimer() { + if (isRunning()){ + try{ + textCurScan.setText(getGlobalVar("CURRENT_REGION").toString()); + } catch(Exception ex){ + getLogger().log(Level.WARNING, null, ex); + textCurScan.setText(""); + } + try{ + int index = (Integer)getGlobalVar("CURRENT_INDEX"); + for (int row=0; row getArgs() { + HashMap args = new HashMap<>(); + + ArrayList regions = new ArrayList(); + for (int i = 0; i < model.getRowCount(); i++) { + if (Boolean.TRUE.equals(model.getValueAt(i, 0))){ + ArrayList region = new ArrayList(); + region.add(model.getValueAt(i, 1)); + region.add(model.getValueAt(i, 2)); + regions.add(region); + } + } + + args.put("FILE", null); + args.put("NAME", getScanName()); + args.put("REGIONS", regions); + return args; + } + + @Override + protected void onStartingExecution(Map args){ + table.clearSelection(); + } + + @Override + protected void onFinishedExecution(Map args, Object ret, Throwable t){ + } + + @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 = EncoderJson.encode(data, true); + Files.write(currentFile.toPath(), json.getBytes()); + updateButtons(); + } + + @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[][][]) EncoderJson.decode(json, Object[][][].class); + textName.setText(String.valueOf(vector[0][0][0])); + model.setDataVector(vector[1], SwingUtils.getTableColumnNames(table)); + } + updateButtons(); + } + + + Map showScientaParametersDialog(Map pars) throws Exception{ + Class cls = getContext().getClassByName("ScientaParametersDialog"); + Constructor constructor= cls.getConstructor(Window.class, boolean.class, Map.class); + StandardDialog dlg = (StandardDialog) constructor.newInstance(getWindow(),true, pars); + dlg.setVisible(true); + if (dlg.getResult()){ + return (Map)cls.getMethod("getValues").invoke(dlg); + } + return null; + } + + protected void updateButtons() { + boolean editing = !isExecuting(); + int rows = model.getRowCount(); + int cur = table.getSelectedRow(); + buttonUp.setEnabled((rows > 0) && (cur > 0) && editing); + buttonDown.setEnabled((rows > 0) && (cur >= 0) && (cur < (rows - 1)) && editing); + buttonDelete.setEnabled((rows > 0) && (cur >= 0) && editing); + buttonInsert.setEnabled(editing); + buttonClear.setEnabled(editing); + buttonOpen.setEnabled(editing); + table.setEnabled(editing); + textName.setEnabled(editing); + } + + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + jScrollPane2 = new javax.swing.JScrollPane(); + jEditorPane1 = new javax.swing.JEditorPane(); + buttonStart = new javax.swing.JButton(); + buttonAbort = new javax.swing.JButton(); + buttonScienta = new javax.swing.JButton(); + jPanel2 = new javax.swing.JPanel(); + jLabel1 = new javax.swing.JLabel(); + textName = new javax.swing.JTextField(); + buttonOpen = new javax.swing.JButton(); + buttonSave = new javax.swing.JButton(); + jScrollPane1 = new javax.swing.JScrollPane(); + table = new javax.swing.JTable(); + buttonInsert = new javax.swing.JButton(); + buttonDelete = new javax.swing.JButton(); + buttonClear = new javax.swing.JButton(); + buttonUp = new javax.swing.JButton(); + buttonDown = new javax.swing.JButton(); + jLabel2 = new javax.swing.JLabel(); + textFileId = new javax.swing.JTextField(); + buttonResetId = new javax.swing.JButton(); + jLabel4 = new javax.swing.JLabel(); + textCurScan = new javax.swing.JTextField(); + buttonAddToQueue = new javax.swing.JButton(); + + jScrollPane2.setViewportView(jEditorPane1); + + buttonStart.setText("Start"); + buttonStart.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonStartActionPerformed(evt); + } + }); + + buttonAbort.setText("Abort"); + buttonAbort.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonAbortActionPerformed(evt); + } + }); + + buttonScienta.setText("Scienta Panel"); + buttonScienta.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonScientaActionPerformed(evt); + } + }); + + jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters")); + + jLabel1.setText("Name:"); + + textName.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + textNameActionPerformed(evt); + } + }); + + buttonOpen.setText("Open"); + buttonOpen.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonOpenActionPerformed(evt); + } + }); + + buttonSave.setText("Save"); + buttonSave.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonSaveActionPerformed(evt); + } + }); + + table.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + + }, + new String [] { + "Enabled", "Region Name", "Arguments" + } + ) { + Class[] types = new Class [] { + java.lang.Boolean.class, java.lang.Object.class, java.lang.String.class + }; + boolean[] canEdit = new boolean [] { + true, true, false + }; + + public Class getColumnClass(int columnIndex) { + return types [columnIndex]; + } + + public boolean isCellEditable(int rowIndex, int columnIndex) { + return canEdit [columnIndex]; + } + }); + table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + table.addMouseListener(new java.awt.event.MouseAdapter() { + public void mouseReleased(java.awt.event.MouseEvent evt) { + tableMouseReleased(evt); + } + }); + table.addKeyListener(new java.awt.event.KeyAdapter() { + public void keyReleased(java.awt.event.KeyEvent evt) { + tableKeyReleased(evt); + } + }); + jScrollPane1.setViewportView(table); + + buttonInsert.setText("Insert"); + buttonInsert.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonInsertActionPerformed(evt); + } + }); + + buttonDelete.setText("Delete"); + buttonDelete.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonDeleteActionPerformed(evt); + } + }); + + buttonClear.setText("Clear"); + buttonClear.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonClearActionPerformed(evt); + } + }); + + buttonUp.setText("Move Up"); + buttonUp.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonUpActionPerformed(evt); + } + }); + + buttonDown.setText("Move Down"); + buttonDown.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonDownActionPerformed(evt); + } + }); + + javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); + jPanel2.setLayout(jPanel2Layout); + jPanel2Layout.setHorizontalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addGroup(jPanel2Layout.createSequentialGroup() + .addComponent(jLabel1) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textName) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonClear) + .addGap(5, 5, 5) + .addComponent(buttonOpen) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonSave)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup() + .addComponent(buttonUp) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonDown) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(buttonInsert) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(buttonDelete))) + .addContainerGap()) + ); + + jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonDelete, buttonDown, buttonInsert, buttonUp}); + + jPanel2Layout.setVerticalGroup( + jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel2Layout.createSequentialGroup() + .addContainerGap() + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(textName) + .addComponent(jLabel1) + .addComponent(buttonOpen) + .addComponent(buttonSave) + .addComponent(buttonClear)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonInsert) + .addComponent(buttonDelete) + .addComponent(buttonUp) + .addComponent(buttonDown)) + .addContainerGap()) + ); + + jLabel2.setText("File ID:"); + + textFileId.setEditable(false); + textFileId.setHorizontalAlignment(javax.swing.JTextField.CENTER); + + buttonResetId.setText("Reset"); + buttonResetId.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + buttonResetIdActionPerformed(evt); + } + }); + + jLabel4.setText("Current Region:"); + + textCurScan.setEditable(false); + textCurScan.setHorizontalAlignment(javax.swing.JTextField.CENTER); + + 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 layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addGap(0, 0, 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)) + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addGroup(layout.createSequentialGroup() + .addComponent(jLabel4) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textCurScan, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(buttonScienta, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(18, 18, Short.MAX_VALUE) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(buttonAddToQueue) + .addGap(18, 18, Short.MAX_VALUE) + .addComponent(jLabel2) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(textFileId, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(buttonResetId, javax.swing.GroupLayout.Alignment.TRAILING)) + .addContainerGap()))) + ); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonAbort, buttonStart}); + + layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonResetId, textCurScan, textFileId}); + + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(7, 7, 7) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel2) + .addComponent(textFileId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(jLabel4) + .addComponent(textCurScan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(buttonAddToQueue)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonResetId) + .addComponent(buttonScienta)) + .addGap(18, 18, 18) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(buttonStart) + .addComponent(buttonAbort)) + .addContainerGap()) + ); + }// //GEN-END:initComponents + + private void buttonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonStartActionPerformed + try { + execute(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonStartActionPerformed + + private void buttonAbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAbortActionPerformed + try { + abort(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonAbortActionPerformed + + private void buttonScientaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonScientaActionPerformed + try { + this.showDevicePanel("scienta"); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonScientaActionPerformed + + private void buttonResetIdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonResetIdActionPerformed + try { + this.getContext().setFileSequentialNumber(0); + updateSeq(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonResetIdActionPerformed + + private void buttonOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOpenActionPerformed + try { + open(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonOpenActionPerformed + + private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed + try { + JFileChooser chooser = new JFileChooser(getContext().getSetup().expandPath(getHomePath())); + FileNameExtensionFilter filter = new FileNameExtensionFilter(getDescription(), getExtensions()); + chooser.setFileFilter(filter); + try { + if (currentFile != null) { + chooser.setSelectedFile(currentFile); + } else if (getScanName() != null) { + File file = Paths.get(chooser.getCurrentDirectory().getAbsolutePath(), getScanName()).toFile(); + chooser.setSelectedFile(file); + } + } catch (Exception ex) { + this.showException(ex); + } + int rVal = chooser.showSaveDialog(this); + if (rVal == JFileChooser.APPROVE_OPTION) { + String fileName = chooser.getSelectedFile().getAbsolutePath(); + if (IO.getExtension(chooser.getSelectedFile().getAbsolutePath()).isEmpty()) { + fileName += "." + FILE_EXTENSION; + } + saveAs(fileName); + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonSaveActionPerformed + + private void buttonAddToQueueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAddToQueueActionPerformed + try { + //queue(getFileName()!=null); //If file is defined then queue file. + queue(); //Queue editing parameters + } catch (Exception ex) { + showException( ex); + } + }//GEN-LAST:event_buttonAddToQueueActionPerformed + + private void textNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textNameActionPerformed + // TODO add your handling code here: + }//GEN-LAST:event_textNameActionPerformed + + private void buttonClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonClearActionPerformed + try { + open(null); + } catch (Exception ex) { + showException( ex); + } + }//GEN-LAST:event_buttonClearActionPerformed + + private void buttonInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonInsertActionPerformed + try { + Map pars = showScientaParametersDialog(null); + if (pars!=null){ + String name = (String) pars.get("name"); + if (name!=null){ + pars.remove("name"); + String json = EncoderJson.encode(pars, true); + model.addRow(new Object[]{true, name, json}); + updateButtons(); + } + } + } catch (Exception ex) { + showException( ex); + } + }//GEN-LAST:event_buttonInsertActionPerformed + + private void buttonDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDeleteActionPerformed + try { + if ((model.getRowCount() > 0) && (table.getSelectedRow() >= 0)) { + model.removeRow(table.getSelectedRow()); + updateButtons(); + } + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonDeleteActionPerformed + + private void buttonUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUpActionPerformed + try { + int rows = model.getRowCount(); + int cur = table.getSelectedRow(); + model.moveRow(cur, cur, cur - 1); + table.setRowSelectionInterval(cur - 1, cur - 1); + updateButtons(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonUpActionPerformed + + private void buttonDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDownActionPerformed + try { + int rows = model.getRowCount(); + int cur = table.getSelectedRow(); + model.moveRow(cur, cur, cur + 1); + table.setRowSelectionInterval(cur + 1, cur + 1); + updateButtons(); + } catch (Exception ex) { + showException(ex); + } + }//GEN-LAST:event_buttonDownActionPerformed + + private void tableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tableKeyReleased + updateButtons(); + }//GEN-LAST:event_tableKeyReleased + + private void tableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableMouseReleased + updateButtons(); + }//GEN-LAST:event_tableMouseReleased + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton buttonAbort; + private javax.swing.JButton buttonAddToQueue; + private javax.swing.JButton buttonClear; + private javax.swing.JButton buttonDelete; + private javax.swing.JButton buttonDown; + private javax.swing.JButton buttonInsert; + private javax.swing.JButton buttonOpen; + private javax.swing.JButton buttonResetId; + private javax.swing.JButton buttonSave; + private javax.swing.JButton buttonScienta; + private javax.swing.JButton buttonStart; + private javax.swing.JButton buttonUp; + private javax.swing.JEditorPane jEditorPane1; + private javax.swing.JLabel jLabel1; + private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel4; + private javax.swing.JPanel jPanel2; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JScrollPane jScrollPane2; + private javax.swing.JTable table; + private javax.swing.JTextField textCurScan; + private javax.swing.JTextField textFileId; + private javax.swing.JTextField textName; + // End of variables declaration//GEN-END:variables + +} diff --git a/script/templates/XPS.py b/script/templates/XPS.py new file mode 100644 index 0000000..abe15d0 --- /dev/null +++ b/script/templates/XPS.py @@ -0,0 +1,84 @@ +import json + +CURRENT_REGION = "" +CURRENT_INDEX = -1 + +if get_exec_pars().debug: + print "Setting debug parameters" + NAME = None + FILE = None + R1 = """{ + "scienta.elementSet" : "HiPPHAXPES", + "scienta.lensMode" : "T_HiPPHAXPES", + "scienta.lowEnergy" : 387.0, + "scienta.acquisitionMode" : "Swept", + "scienta.slices" : 1.0, + "scienta.stepSize" : 0.25, + "scienta.passEnergy" : 2, + "scienta.detectorMode" : "ADC", + "scienta.energyMode" : "Kinetic", + "scienta.centerEnergy" : 397.0, + "scienta.stepTime" : 1.0, + "scienta.highEnergy" : 407.0, + "scienta.iterations" : 1.0 + } """ + + REGIONS = [["R1", R1]] + +if FILE: + FILE = get_context().setup.expandPath("{home}/parameters/" + FILE) + with open(FILE) as json_file: + cfg = json.load(json_file) + NAME , REGIONS= cfg[0][0][0], cfg[1] + print "FILE: ", FILE +print "NAME: ", NAME +#print "REGIONS: ", REGIONS + + +set_device_alias(scienta.getSpectrum(), "spectrum") +set_device_alias(scienta.getDataMatrix(), "image") +set_device_alias(scienta.stats[0], "sum") + +sensors=[i0, scienta.stats[0], scienta.getSpectrum()] + + +def apply_pars(pars): + scienta.elementSet = scienta.elementSet.valueOf(pars["scienta.elementSet"]) + scienta.lensMode = scienta.lensMode.valueOf(pars["scienta.lensMode"]) + scienta.detectorMode = scienta.detectorMode.valueOf(pars["scienta.detectorMode"]) + scienta.energyMode = scienta.energyMode.valueOf(pars["scienta.energyMode"]) + scienta.acquisitionMode = scienta.acquisitionMode.valueOf(pars["scienta.acquisitionMode"]) + scienta.passEnergy = pars["scienta.passEnergy"] + scienta.getLowEnergy().writeAsync(pars["scienta.centerEnergy"]) + scienta.getCenterEnergy().writeAsync(pars["scienta.passEnergy"]) + scienta.getHighEnergy().writeAsync(pars["scienta.highEnergy"]) + scienta.getSlices().writeAsync(pars["scienta.slices"]) + scienta.getStepSize().writeAsync(pars["scienta.stepSize"]) + scienta.getStepTime().writeAsync(pars["scienta.stepTime"]) + scienta.setIterations(int(pars["scienta.iterations"])) + + + +def before_read(position, scan): + #trigger_scienta() + pass + + +#dummy_trigger_scienta() + + +try: + for r in REGIONS: + name=r[0] + pars = json.loads(r[1]) + CURRENT_REGION = name + CURRENT_INDEX = CURRENT_INDEX+1 + print "Region: ", name + print "Pars: ", pars + apply_pars(pars) + time.sleep(5.0) + + #tscan(sensors, 1, 0.001, before_read=before_read, after_read=after_readout, name = NAME) +finally: + scienta.zeroSupplies() + diff --git a/script/test/TestScientaParsPanel.py b/script/test/TestScientaParsPanel.py new file mode 100644 index 0000000..807f596 --- /dev/null +++ b/script/test/TestScientaParsPanel.py @@ -0,0 +1,27 @@ +import ch.psi.utils.swing.SwingUtils as SwingUtils +import ScientaParametersPanel +import ScientaParametersDialog + +""" +pn = ScientaParametersPanel() +pn.setDevice(scienta) +SwingUtils.showDialog(App.getInstance().getMainFrame(), "Scienta", None, pn) +time.sleep(1.0) +pars = pn.values +for k in pars.keySet() : print k,"=",pars[k] +""" + + +dlg = ScientaParametersDialog(App.getInstance().getMainFrame(),True, None) +dlg.visible=True +if dlg.result: + pars = dlg.values + for k in pars.keySet() : print k,"=",pars[k] + + + dlg = ScientaParametersDialog(App.getInstance().getMainFrame(),True, pars) + dlg.visible=True + if dlg.result: + pars = dlg.values + for k in pars.keySet() : print k,"=",pars[k] + \ No newline at end of file